Collection::splice return empty #52252
Unanswered
foremtehan
asked this question in
General
Replies: 1 comment
-
From what I see you want to insert some element Not sure the splice method was made to be used fluently for this type of case. And a proposal about an insert in Collection was rejected : laravel/ideas#650 This code is a bit tricky but seems to work fluently (using variables for better understanding) : $collection = collect([1, 2, 3]);
$insertionIndex = 1;
$insertionValue = 4;
$collection->slice(0, $insertionIndex)->push($insertionValue)->merge($collection->splice($insertionIndex))->dump(); |
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.
-
What if i want to use fluent syntax after calling
splice
method ?Beta Was this translation helpful? Give feedback.
All reactions