php初心者です。
php
1$studentList = [ 2 0 => '1,student,taro', 3 1 => '1,student,hanako', 4 2 => '1,student,hoge' 5];
1 => [ student => [ 0 => taro, 1 => hanako, 2 => hoge ] ]
上記のような配列$studentListをカンマで分解し多次元配列を作成したいのですが、自分が作成したループ
php
1foreach ($studentList as $key => $value) { 2 $explodedValue = explode(',', $value); 3 $arrResult = [ 4 $explodedValue[0] => [ 5 $explodedValue[1] => [$key => $explodedValue[2]] 6 ] 7 ]; 8}
では実行結果が、
1 => [ student => [ 2 => hoge ] ]
このようになってしまいます。当たり前といえば当たり前なのですが、期待する結果のような配列を作るには、どうしたらいいでしょうか?
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/01 12:42