あじちゃんのブログ。備忘録。

〜SEもOLなんですかね?

連想配列が格納された配列

$input   =   ('id'       => '52738495'
             'name'     => 'ねこ'
             'birthday' => '2000/01/31');

↑みたいな連想配列を作りたい。

  • できた
$values = array(100,200,300,400,500);

$data = [];  //全体の配列

foreach($values as $value) {
    $item = array('id'=>$value, 'name'=>'ねこ','birthday'=>'2000/01/31');
    array_push($data,$item);
}
echo "<pre>";
print_r($data);
echo "</pre>";
//出力
Array
(
    [0] => Array
        (
            [id] => 100
            [name] => ねこ
            [birthday] => 2000/01/31
        )

    [1] => Array
        (
            [id] => 200
            [name] => ねこ
            [birthday] => 2000/01/31
        )

    [2] => Array
        (
            [id] => 300
            [name] => ねこ
            [birthday] => 2000/01/31
        )

    [3] => Array
        (
            [id] => 400
            [name] => ねこ
            [birthday] => 2000/01/31
        )

    [4] => Array
        (
            [id] => 500
            [name] => ねこ
            [birthday] => 2000/01/31
        )

)