ok Posted December 3, 2008 Share Posted December 3, 2008 what is wrong with this codes? <?php //Testing multi-dimentional array echo "<h3>Multi-Dimentional Array test.</h3>"; echo "<br>"; for($i=0; $i<=10; $i++) { $names[]=$i; } echo "<br>"; echo "<b>Single array</b>"; echo "<br>"; echo "<b>print_r</b>"; echo "<pre>"; print_r($names); echo "</pre>"; echo "<br>"; echo "<b>Multi array</b>"; echo "<br>"; for($i=0; $i<=10; $i++) { $names[$i][$i]=$i; } echo "<b>print_r</b>"; echo "<pre>"; print_r($names); echo "</pre>"; ?> Thank you in advance Quote Link to comment Share on other sites More sharing options...
xtopolis Posted December 3, 2008 Share Posted December 3, 2008 Second loop, you need to declare that it is an array first. for($i=0; $i<=10; $i++) { $names[$i]=array(); $names[$i][$i]=$i; } Quote Link to comment Share on other sites More sharing options...
btherl Posted December 3, 2008 Share Posted December 3, 2008 This is only a problem because you used $names as a 1-level array first, and then used it as a 2-level array. If you use a fresh variable you should not have any problems making the 2-level array. Quote Link to comment Share on other sites More sharing options...
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.