[PHP]配列の値だけの配列を作る

配列の値だけの配列を作る

$data=array();
$data['jack']=array( 'gender'=>'male', 'size'=>198, 'status'=>array('QK',32,'skyhigh','log'=>array('20120303','20120529','20121111') ) );
$data['jeff']=array( 4,87,8,4,3 );
$data['pole']=array( 'address'=>'earth', 'phone number'=>'39028502753' );

echo '<pre>';
var_dump( getValuesByArray($data) );
echo '</pre>';

function getValuesByArray($targetArray){
    if( !is_array($targetArray) ){
        return array($targetArray);
    }
    $tmp=array();
    foreach($targetArray as $key => $value){
        $tmp=array_merge($tmp, getValuesByArray($value) );
    }
    return $tmp;
}

出力結果

array(15) {
  [0]=>
  string(4) "male"
  [1]=>
  int(198)
  [2]=>
  string(2) "QK"
  [3]=>
  int(32)
  [4]=>
  string(7) "skyhigh"
  [5]=>
  string(8) "20120303"
  [6]=>
  string(8) "20120529"
  [7]=>
  string(8) "20121111"
  [8]=>
  int(4)
  [9]=>
  int(87)
  [10]=>
  int(8)
  [11]=>
  int(4)
  [12]=>
  int(3)
  [13]=>
  string(5) "earth"
  [14]=>
  string(11) "39028502753"
}

サンプル