jimfog Posted April 20, 2012 Share Posted April 20, 2012 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 comment Share on other sites More sharing options...
Ingolme Posted April 20, 2012 Share Posted April 20, 2012 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 comment Share on other sites More sharing options...
thescientist Posted April 20, 2012 Share Posted April 20, 2012 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 Link to comment Share on other sites More sharing options...
www.web0752.com Posted April 22, 2012 Share Posted April 22, 2012 just learn it... Link to comment Share on other sites More sharing options...
jimfog Posted May 2, 2012 Author Share Posted May 2, 2012 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 comment Share on other sites More sharing options...
dsonesuk Posted May 2, 2012 Share Posted May 2, 2012 for($i=0;$i<count($list);$i++) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.