warhead2020 Posted June 19, 2008 Share Posted June 19, 2008 hello,I need some help.... I want to display the content of my array but i dont have any idea coz the size of the second [] not the same. Here is the array:- array1[0][0]=1; array1[0][1]=2; array1[1][0]=3; array1[1][1]=4; array1[1][2]=5; array1[2][0]=6; array1[3][0]=7; array1[3][1]=8; Hope someone out there can help me solve this problem. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/110850-display-array-2-dimensional/ Share on other sites More sharing options...
cunoodle2 Posted June 19, 2008 Share Posted June 19, 2008 Try this... <?php $count = count ($array_name); for ($i=0; $i<$count; $i++){ $countmore=count($array_name[0]); for ($j=0; $j < $countmore; $j++){ print ("i$i j$j " . $array_name[$i][$j] . "<br /> "); } print ("<br />"); } ?> Something like that. Try it out and let me know what you come up with. I have not tested that code at all. Link to comment https://forums.phpfreaks.com/topic/110850-display-array-2-dimensional/#findComment-568741 Share on other sites More sharing options...
warhead2020 Posted June 19, 2008 Author Share Posted June 19, 2008 Quote Try this... <?php $count = count ($array_name); for ($i=0; $i<$count; $i++){ $countmore=count($array_name[0]); for ($j=0; $j < $countmore; $j++){ print ("i$i j$j " . $array_name[$i][$j] . "<br /> "); } print ("<br />"); } ?> Something like that. Try it out and let me know what you come up with. I have not tested that code at all. can u pls explain what is the diferent between this 2... --> $countmore=count($array_name[0]); --> $count = count ($array_name); i know it count the size but im stil not clear with it(sorry..Im beginner.. ).. Thanks in advance.. Link to comment https://forums.phpfreaks.com/topic/110850-display-array-2-dimensional/#findComment-568763 Share on other sites More sharing options...
whizard Posted June 19, 2008 Share Posted June 19, 2008 $count will hold the number of second-dimension arrays; $countmore holds the size of $array[0]. Link to comment https://forums.phpfreaks.com/topic/110850-display-array-2-dimensional/#findComment-568767 Share on other sites More sharing options...
whizard Posted June 19, 2008 Share Posted June 19, 2008 I think he meant $countmore=count($array_name[$i]); Link to comment https://forums.phpfreaks.com/topic/110850-display-array-2-dimensional/#findComment-568769 Share on other sites More sharing options...
kenrbnsn Posted June 19, 2008 Share Posted June 19, 2008 You can also use the "foreach" loop: <?php $array[0][0]=1; $array[0][1]=2; $array[1][0]=3; $array[1][1]=4; $array[1][2]=5; $array[2][0]=6; $array[3][0]=7; $array[3][1]=8; foreach ($array as $top => $sec) { $tmp = array(); foreach ($sec as $i => $val) $tmp[] = "\$array[$top][$i] = $val"; echo implode(' | ',$tmp) . '<br>'; } ?> Ken Link to comment https://forums.phpfreaks.com/topic/110850-display-array-2-dimensional/#findComment-568770 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.