Re: [PHP] xarray - The missing array functions you are looking for, implemented in Extension
- Date: Fri, 16 Oct 2015 09:31:31 +0100
- From: Ashley Sheridan <ash@xxxxxxxxxxxxxxxxxxxx>
- Subject: Re: [PHP] xarray - The missing array functions you are looking for, implemented in Extension
On 16 October 2015 08:58:55 BST, Lin Yo-an <cornelius.howl@xxxxxxxxx> wrote:
>New function added to xarray extension:
>$array = [
> "created_at" => ...
> "updated_at" => ....
> "_at" => "_on",
>> On Oct 15, 2015, at 12:40, Lin Yo-an <cornelius.howl@xxxxxxxxx>
>> On Oct 15, 2015, at 06:44, Ryan Pallas <derokorian@xxxxxxxxx> wrote:
>>> array_pluck is in the language, called array_column
>> array_pluck is designed to support dot expression, for example:
>> array_pluck($array, "parent.child.child1.attr");
>>> array_remove is just array_filter, why do I need another function
>> array_filter only passes value to the callback. in PHP 5.6, there is
>a new option to pass both key and value,
>> however PHP 5.5 doesn't have this option.
>> Implementing this function in extension make it possible.
>>> array_add - why do I need the overhead of a function call, when I
>can do $a[
>>> *key*] = *value*
>> The reason has been described in the document: array_add only adds
>data when the key doesn't exist.
>> You can treat it as a set operation.
>> $array = [ ];
>> array_add($array, "key", 10); // key => 10, return true
>> array_add($array, "key", 20); // key => 10 still, return false
>>> array_build - this seems neat, but I think it needs a better
>example, I can
>>> do the example already with array_combine(array_column(),
>> By using array_build, you can pass complex structure as the new
>value, or adding complex logic in the callback.
>>> array_each - this is just a foreach with an isolated scope and
>>> overhead on every iteration, why would I want that?
>> Yeah I have to admit it's pretty much similar, however sometimes you
>want to pass a iteration handler from external,
>> and array_map returns a new array, array_each is faster than
>array_map because it's much lightweight and it doesn't return value.
>>> array_keys_join - while I like this, why doesn't it have the same
>>> order as implode/join (glue, array)?
>> The reason I put array as the first argument is, consistency. and
>actually the "glue" is optional, so you can simply ignore the argument.
>> $key = array_keys_join($array);
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
Please can you try to not top post, it really makes it more difficult to read the thread, and the rules do state that replies should be inline quoted or bottom posted
Sent from my Android device with K-9 Mail. Please excuse my brevity.
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php