I have an array like below :
array:3 [ "2021-08-07" => array:3 [ "id" => "1" "date" => "2021-08-07" "numbers" => array:2 [ 0 => 1 1 => 2 ] ] "2021-08-08" => array:3 [ "id" => "1" "date" => "2021-08-08" "numbers" => array:2 [ 0 => 1 1 => 2 ] ] ]
What I want to do is simply to remote the parent 2021-08-08
items because I have the date inside the array already . Now, what I have tried so far is :
$result = array_map(function ($el){ return $el[0]; },$test); dd($result);
But it gives me error of undefined index[0]
. what I want this array to look like is like below :
array:3 [ "id" => "1" "date" => "2021-08-07" "numbers" => array:2 [ 0 => 1 1 => 2 ], "id" => "1" "date" => "2021-08-08" "numbers" => array:2 [ 0 => 1 1 => 2 ] ]
Advertisement
Answer
Won’t just array_values()
do?
array_values($test);