3v4l.org

run code in 300+ PHP versions simultaneously
<?php if(!function_exists('is_assoc')){ function is_assoc($array) { return (bool)count(array_filter(array_keys($array), 'is_string')); } } /** * getCols * * Takes an array of associative arrays and combines them to get * the columns * * @author Joe Richardson * @access public * @return object Instance of DB or Null */ function getCols(array $data) { if(is_assoc($data)){ return $data; }else{ return (array)call_user_func_array('array_merge_recursive',$data); } } $a = array( array( 'id' => 1 , 'name' => 'foo' , 'date' => date() ) , array( 'id' => 2 , 'name' => 'bar' , 'date' => date() ) , array( 'id' => 3 , 'name' => 'george' , 'date' => date() ) , array( 'id' => 4 , 'name' => 'burdell' , 'date' => date() ) ); $b = getCols($a); var_dump($b);

preferences:
37.67 ms | 402 KiB | 5 Q