Jump to content


Photo

How would you print this array values?


  • Please log in to reply
2 replies to this topic

#1 bilis_money

bilis_money
  • Members
  • PipPipPip
  • Advanced Member
  • 621 posts

Posted 13 July 2006 - 10:08 PM

guys?

ok, let say i have these array structure:

Array
(
    [s_id] => 91
    [s_photo_filename] => logo03.gif
    [s_tmp_name] => 
    [s_type] => image/gif
    [s_size] => 4612
    [s_path] => 
    [s_date] => 2006-06-25
    [s_comments] => TEsting, testing
    [s_photo_category] => 
)

now i know that the keys of the array are in string and not in intergers.
how would you loop and move the array pointer from 0 to 9?

i know these codes below are not possible because the array keys is in strings.
	while($i < 9) {
			$result = $_session[$i]; //this will not work
			echo "$i: ". $result. "<br>";
			$i++;
	}

now what's your way of solving this?


thanks in advance.


#2 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 13 July 2006 - 10:13 PM

I think this will do it:
$i=0;
foreach($arrayName as $key=>$value) {
			$result = $_session[$key]; //this will not work
			echo "$i: ". $result. "<br>";
			$i++;
$i++;
}

<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#3 bilis_money

bilis_money
  • Members
  • PipPipPip
  • Advanced Member
  • 621 posts

Posted 13 July 2006 - 11:24 PM

ok thanks i'll try to understand foreach again.
i have just forgot the essence of it.

thanks anyway.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users