0

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
  ]
]
SEYED BABAK ASHRAFI
  • 4,093
  • 4
  • 22
  • 32
Farshad
  • 1,830
  • 6
  • 38
  • 70

2 Answers2

3

Won't just array_values() do?

array_values($test);
shaedrich
  • 5,457
  • 3
  • 26
  • 42
1
$test = array_values(yourArray);
$test = (object)$yourArray;