Replies: 3 comments 5 replies
-
$last would be confusing and can give unwanted results for users that use or need double quotes. |
Beta Was this translation helpful? Give feedback.
0 replies
-
this for append field for index have not field and add value default 5 for push (specific index dont use * ) array u must have specific last index +1 and user function |
Beta Was this translation helpful? Give feedback.
2 replies
-
JavaScript had a similar problem and therefor added the |
Beta Was this translation helpful? Give feedback.
3 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.
-
In python we are able to get a reference to the last element of an array with this syntax:
arr[-1] = "test"
this is much better than the current PHP's syntax:
arr[array_key_last(arr)] = "test"
This the difference is especially noticeable when accessing the leaf nodes of a nested container (my use case for this feature):
Python:
compare to PHP:
We could have this same conveniences on Laravel by adding special macros to the dot notation:
Arr::set($animals, '$last.members.$last.members', 'human');
I'm not sure which syntax to use, may be this belongs on a different method or something. But those features are used a lot in the python world to simplify data manipulation and would add a lot of value to to the
Arr
helper methods.Beta Was this translation helpful? Give feedback.
All reactions