How to print multidimensional array?

Discussion in 'PHP' started by rahulephp, Dec 9, 2009.

  1. #1
    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
            )
    
    )
    
    Code (markup):
    Please let me know, how would be this possible?
     
    rahulephp, Dec 9, 2009 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    foreach($array['temp_property_name'] as $k => $v) {
        echo nl2br('Property Name: '.$array['temp_property_name'][$k].'
    Property Address: '.$array['temp_property_add'][$k].'
    Price: '.$array['temp_property_price'][$k].'
    Property Size: '.$array['temp_property_size'][$k].'
    URL '.$array['temp_property_detail'][$k]);
    }
    PHP:
     
    JAY6390, Dec 9, 2009 IP
  3. rahulephp

    rahulephp Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey thanks buddy,
    This is what i was looking for

    But i did this in another way

    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/>';
     	}
    
    
    
    Code (markup):
    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
    
    Code (markup):
     
    rahulephp, Dec 9, 2009 IP