Categories: PHP

PHPで配列の中身を見る方法

print_r 、 var_dump 、 var_export の3種類。

$array = array('taro'=>array('age'=>20 , 'gender'=>'male'),'hanako'=>array('age'=>18 , 'gender'=>'female'));
print_r($array);
var_dump($array);
var_export($array);

  実行結果

Array
(
    [taro] => Array
        (
            日付未入力 => 20
            [gender] => male
        )

    [hanako] => Array
        (
            日付未入力 => 18
            [gender] => female
        )

)

array(2) {
  ["taro"]=>
  array(2) {
    ["age"]=>
    int(20)
    ["gender"]=>
    string(4) "male"
  }
  ["hanako"]=>
  array(2) {
    ["age"]=>
    int(18)
    ["gender"]=>
    string(6) "female"
  }
}

array (
  'taro' =>
  array (
    'age' => 20,
    'gender' => 'male',
  ),
  'hanako' =>
  array (
    'age' => 18,
    'gender' => 'female',
  ),
)
nakaike