Q:

how to format a array in php?

i have an array $array that prints out something like:
Array
(
[Terry] => Array
    (
        [2011-10-26] => Array
            (
                [0] => 69.90
                [1] => 69.90
            )

    )

[Travis] => Array
    (
        [2011-10-26] => Array
            (
                [0] => 199.50
            )

        [2011-10-27] => Array
            (
                [0] => 199.50
            )

    )
)

i am trying to place data into a table like this:
NAME      2011-10-26     2011-10-27
Terry     2              0
Travis    1              1

i can get the count like this:
foreach($array as $key => $value){  
     echo $key; // this will give me the names
     foreach($value as $keys => $values){
         echo $keys; //this will give me the dates
         echo count($values); // this will give me the count per date
     }
}

the dates that i get back are  like this: 2011-10-26     2011-10-26     2011-10-27
I've been playing with this for a while and i run out of ideas.
any help?
Thanks

A:

// build a list of all of the available dates
$dates = array();
foreach($array as $key => $value){
    $dates = array_merge($value, $dates);
}

$dates = array_keys($dates);

// You may want to sort the date columns here somehow
echo "Names\t".implode("\t",$dates)."\n";
foreach($array as $key => $value){
    echo $key;
    foreach($dates as $d){
        echo "\t".(array_key_exists($d, $value) ? count($value[$d]) : 0);
    }
    echo "\n";
}

