Replies: 2 comments
-
I did not test if it works, but you could try it with a closure like: $collection->keyBy(fn($item) => $item->id); edit: if you're not using php 7.4 yet, you have to use the more expressive syntax for the closure: $collection->keyBy(function($item) {
return $item->id;
}); |
Beta Was this translation helpful? Give feedback.
0 replies
-
In the case of an array key, Strings containing valid integers will be cast to the integer type. E.g. the key "8" will actually be stored under 8. On the other hand, "08" will not be cast, as it isn't a valid decimal integer. Read this reference link and another link |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I was testing the below code in laravel tinker.
results for the above code is
When I changed the id of the first element to a non zero value like the below code
It gives the intended results as below
Is there is a way to get a result like below when there is an element with value zero in laravel collection?
Beta Was this translation helpful? Give feedback.
All reactions