PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
rahulephp
Forum Commoner
Posts: 28 Joined: Mon Oct 05, 2009 11:05 am
Post
by rahulephp » Wed Dec 09, 2009 5:43 am
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?
pbs
Forum Contributor
Posts: 230 Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:
Post
by pbs » Wed Dec 09, 2009 6:24 am
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];
}
?>
jayshields
DevNet Resident
Posts: 1912 Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England
Post
by jayshields » Wed Dec 09, 2009 8:21 am
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];
AbraCadaver
DevNet Master
Posts: 2572 Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:
Post
by AbraCadaver » Wed Dec 09, 2009 10:34 am
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.
mysql_function(): WARNING : This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.