Page 1 of 1

How to print multidimensional array?

Posted: Wed Dec 09, 2009 5:43 am
by rahulephp
Hi
I need to print below array in the following manner.

Output would be:

Property Name: 1
Property Address: 1
Price: 1
Property Size: 1
URL 1

Property Name: 2
Property Address: 2
Price: 2
Property Size: 2
URL 2


Here is array:

Code: Select all

 
 
 
Array
(
    [temp_property_name] => Array
        (
            [0] => Property Name: 1
            [1] => Property Name: 2
        )
 
    [temp_property_add] => Array
        (
            [0] => Property Address: 1
            [1] => Property Address: 2
        )
 
    [temp_property_price] => Array
        (
            [0] => Price: 1
            [1] => Price: 2
        )
 
    [temp_property_size] => Array
        (
            [0] => Property Size: 1
            [1] => Property Size: 2
        )
 
    [temp_property_detail] => Array
        (
            [0] => URL 1
            [1] => URL 2
        )
 
)
 
Please let me know, how would be this possible?

Re: How to print multidimensional array?

Posted: Wed Dec 09, 2009 6:24 am
by pbs
Try this code

Code: Select all

 
<?php
$cnt = count($arr['temp_property_name']);
for($i=0;$i<$cnt;$i++)
{
    echo "<br>Property Name: ".($i+1)." ".$arr['temp_property_name'][$i];
    echo "<br>Property Address: ".($i+1)." ".$arr['temp_property_add'][$i];
    echo "<br>Price: ".($i+1)." ".$arr['temp_property_price'][$i];
    echo "<br>Property Size: ".($i+1)." ".$arr['temp_property_size'][$i];
    echo "<br>URL: ".($i+1)." ".$arr['temp_property_detail'][$i];
}
?>
 

Re: How to print multidimensional array?

Posted: Wed Dec 09, 2009 8:21 am
by jayshields
Your array has been constructed incorrectly, so it's more complicated than it should be.

Code: Select all

 
for($x = 0; $x <= 1 /*amount of properties - 1*/; $x++)
  foreach($array as $v)
    echo $v[$x];

Re: How to print multidimensional array?

Posted: Wed Dec 09, 2009 10:34 am
by AbraCadaver
jayshields wrote:Your array has been constructed incorrectly, so it's more complicated than it should be.

Code: Select all

 
for($x = 0; $x <= 1 /*amount of properties - 1*/; $x++)
  foreach($array as $v)
    echo $v[$x];
Yes, as I posted in the OP's other post: viewtopic.php?f=1&t=109960&p=581824#p581824 They should rethink their array.