jimfog 30 Posted April 20, 2012 Report 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]? Quote Link to post Share on other sites
Ingolme 1,020 Posted April 20, 2012 Report 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] Quote Link to post Share on other sites
thescientist 231 Posted April 20, 2012 Report Share Posted April 20, 2012 (edited) 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 April 20, 2012 by thescientist Quote Link to post Share on other sites
www.web0752.com 0 Posted April 22, 2012 Report Share Posted April 22, 2012 just learn it... Quote Link to post Share on other sites
jimfog 30 Posted May 2, 2012 Author Report 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. Quote Link to post Share on other sites
dsonesuk 913 Posted May 2, 2012 Report Share Posted May 2, 2012 for($i=0;$i<count($list);$i++) Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.