anatak Posted May 5, 2007 Share Posted May 5, 2007 Hello I am banging my head against some array stuff. can someone explain how the syntax works to run through an array ? I have an array $content and in that array is an index $cat_id but I have no idea what the =>$category means Can anyone explain or give me a link to a clear basic tutorial ? I looked a the php page of array functions but I got lost there. foreach ($content as $cat_id=>$category){ } kind regards anatak Link to comment https://forums.phpfreaks.com/topic/50133-solved-help-with-arrays/ Share on other sites More sharing options...
Lumio Posted May 5, 2007 Share Posted May 5, 2007 Hi! I give you two examples: You got an array like that: <?php $arr[0] = 'hello'; $arr[2] = 'foo'; $arr[1] = 'world'; $arr[3] = 'bar'; foreach ($arr as $index => $value) { echo "$index => $value<br>\n"; } ?> You see... the result is the same as you'r definition: 0 => hello 2 => foo 1 => world 3 => bar Now the second example: <?php $arr['hello'] = 'world'; $arr['foo'] = 'bar'; foreach ($arr as $index => $value) { echo "$index => $value<br>\n"; } ?> You also get the index and the value: hello => world foo => bar I think now you know what $index => $value means Link to comment https://forums.phpfreaks.com/topic/50133-solved-help-with-arrays/#findComment-246217 Share on other sites More sharing options...
anatak Posted May 5, 2007 Author Share Posted May 5, 2007 thanks for clarifying this. anatak Link to comment https://forums.phpfreaks.com/topic/50133-solved-help-with-arrays/#findComment-246374 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.