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
  ]
]
1
  • You can also use this solution Commented Aug 4, 2021 at 8:11

2 Answers 2

3

Won't just array_values() do?

array_values($test);
Sign up to request clarification or add additional context in comments.

1 Comment

that was so ez lol :) thanks for help that was the trick
1
$test = array_values(yourArray);
$test = (object)$yourArray;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.