Jump to content

Recommended Posts

here is a piece of code-related to arrays- which i am having difficulty understanding it and i would appreciate some help

for($=0;$i<$lists;$i++){ echo ....$list[i][0] }

There is also some other code but the above is enough for what i want to ask. Why $list[0] has both [0] in front of it? The 0 is to access the first element of the array, what is the role of the loopcounter i there? I think it is there to access all the elements of the array one by one but how exactly does it achieve that by having the counterleft from the array index--[0]?

Link to post
Share on other sites

It should just be $list[$i]. The "i" needs the $ symbol next to it. As for the [0]. It would access the first element of the array contained within $link[$i]

Link to post
Share on other sites

well, it's actually the code that you are leaving out that is important. We can infer the structure of $lists because of the loop, which appears to be multidemensional. A simple way to confirm for yourself is just to output $list. this is a simple appx. of what $list might look like that would work for that loop.

$list = array(  0 => array(0 => 'somevalue'),  1 => array(0 => 'someothervalue'),  2 => array(0 => 'yetsomeothervalue'));

edit: and yes, the loop counter would need to be $i

Edited by thescientist
Link to post
Share on other sites
  • 2 weeks later...
well, it's actually the code that you are leaving out that is important. We can infer the structure of $lists because of the loop, which appears to be multidemensional. A simple way to confirm for yourself is just to output $list. this is a simple appx. of what $list might look like that would work for that loop.
$list = array(  0 => array(0 => 'somevalue'),  1 => array(0 => 'someothervalue'),  2 => array(0 => 'yetsomeothervalue'));

edit: and yes, the loop counter would need to be $i

Yes it must be a multidimensional array.
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...