[ create a new paste ] login | about

Link: http://codepad.org/UnyEZJ6a    [ raw code | output | fork ]

PHP, pasted on Nov 16:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php

$results = array
  ( array('page'=>'duet/faq/horse', 'col0'=>  001 , 'col1' =>  NULL, 'col2' => NULL)
  , array('page'=>'duet/faq/'     , 'col0'=> 'uno', 'col1' => 'dos', 'col2' => NULL)
  , array('page'=>'duet/'         , 'col0'=> 'one', 'col1' => 'two', 'col2' => 'three')
  );

print_r($results);

foreach(array_keys($results[0]) as $key)
  foreach($results as $result) 
    if ($result[$key]){ $final[$key] = $result[$key]; continue 2; }


print_r($final);
?>


Output:
Array
(
    [0] => Array
        (
            [page] => duet/faq/horse
            [col0] => 1
            [col1] => 
            [col2] => 
        )

    [1] => Array
        (
            [page] => duet/faq/
            [col0] => uno
            [col1] => dos
            [col2] => 
        )

    [2] => Array
        (
            [page] => duet/
            [col0] => one
            [col1] => two
            [col2] => three
        )

)
Array
(
    [page] => duet/faq/horse
    [col0] => 1
    [col1] => dos
    [col2] => three
)


Create a new paste based on this one


Comments: