print array with proper indentation

305 Views Asked by At
foreach ( $custom_fields as $field_key => $field_values ) {
    foreach ( $field_values as $key => $value )
        echo $field_key . '<br>';
        echo '<pre>' , print_r( $value,true) , '</pre>';
}

Although I'm using print_r with <pre> tag, the ouput looks like this:

a:4:{i:0;s:6:"Casual";i:1;s:6:"Serene";i:2;s:6:"Unique";i:3;s:9:"Whimsical";}

shouldn't it be listed vertically with proper indentation? What am I doing wrong?

2

There are 2 best solutions below

2
On BEST ANSWER

This is a serialized array, use unserialize() to turn it back to an array again:

foreach ( $custom_fields as $field_key => $field_values ) {
    foreach ( $field_values as $key => $value ) {
        $value = unserialize($value);
        echo $field_key . '<br/>';
        echo '<pre>' , print_r($value, true) , '</pre>';
    } 
}

What it would look like:

http://codepad.viper-7.com/5Rppb3

0
On

you can use only

    $value=unserialize($custom_fields); 
    echo '<pre>' ;    
    var_dump($value);
    echo '</pre>';