rahulephp Posted December 9, 2009 Share Posted December 9, 2009 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: 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? Quote Link to comment https://forums.phpfreaks.com/topic/184515-how-to-print-multidimensional-array/ Share on other sites More sharing options...
trq Posted December 9, 2009 Share Posted December 9, 2009 This has what to do with mysql? Quote Link to comment https://forums.phpfreaks.com/topic/184515-how-to-print-multidimensional-array/#findComment-974081 Share on other sites More sharing options...
rahulephp Posted December 9, 2009 Author Share Posted December 9, 2009 Hi solution1: I have did this in following way $child_count = count($temp_property_detail['temp_property_name']); db($child_count); //exit; for($i = 0; $i <= child_count+1; $i++) { echo $temp_property_detail['temp_property_name'][$i].'<br/>'; echo $temp_property_detail['temp_property_add'][$i].'<br/>'; echo $temp_property_detail['temp_property_price'][$i].'<br/>'; echo $temp_property_detail['temp_property_size'][$i].'<br/>'; echo $temp_property_detail['temp_property_detail'][$i].'<br/>'; echo '<br/>'; } and output is: Debug: 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 But please let me know, how can we do same thing with using "FOREACH" loop? Quote Link to comment https://forums.phpfreaks.com/topic/184515-how-to-print-multidimensional-array/#findComment-974091 Share on other sites More sharing options...
salathe Posted December 9, 2009 Share Posted December 9, 2009 But please let me know, how can we do same thing with using "FOREACH" loop? I'm not entirely sure why you can't arrive at this on your own (is there really such a huge leap between for and foreach?). Here's one way of doing it: foreach ($temp_property_detail['temp_property_name'] as $i => $name) { echo $temp_property_detail['temp_property_name'][$i].'<br/>'; echo $temp_property_detail['temp_property_add'][$i].'<br/>'; echo $temp_property_detail['temp_property_price'][$i].'<br/>'; echo $temp_property_detail['temp_property_size'][$i].'<br/>'; echo $temp_property_detail['temp_property_detail'][$i].'<br/>'; echo '<br/>'; } Quote Link to comment https://forums.phpfreaks.com/topic/184515-how-to-print-multidimensional-array/#findComment-974097 Share on other sites More sharing options...
cags Posted December 9, 2009 Share Posted December 9, 2009 foreach ($temp_property_detail['temp_property_name'] as $i => $name) { echo $name.'<br/>'; echo $temp_property_detail['temp_property_add'][$i].'<br/>'; echo $temp_property_detail['temp_property_price'][$i].'<br/>'; echo $temp_property_detail['temp_property_size'][$i].'<br/>'; echo $temp_property_detail['temp_property_detail'][$i].'<br/>'; echo '<br/>'; } Quote Link to comment https://forums.phpfreaks.com/topic/184515-how-to-print-multidimensional-array/#findComment-974109 Share on other sites More sharing options...
rahulephp Posted December 10, 2009 Author Share Posted December 10, 2009 Hey, thank you very much. I do appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/184515-how-to-print-multidimensional-array/#findComment-974592 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.