Jump to content

Display Array 2 Dimensional


warhead2020

Recommended Posts

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

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.

  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..

 

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.