Salta al contenuto principale


 array_map(?callable $callback, array $array, array ...$arrays): array
 array_filter(array $array, ?callable $callback = null, int $mode = 0): array

why.

in reply to Fabio

@Fabio Because in the first case you have a variable amount of input array parameters but only one callback parameter, and in the second case you have only one input array parameter but two optional parameters 🙃
in reply to Fabio

@Hypolite Petovan of course, a "filter" function must have a nullable callback... my bad. what I was thinking?
in reply to Fabio

@Fabio

If no callback is supplied, all empty entries of array will be removed.


It is pretty handy tho.

in reply to Fabio

@Hypolite Petovan

If no callback is supplied, all empty entries of array will be removed.


array_filter() gets the array by value, so no entries are "removed". you always get a new array.

so why not just $empty_array = [];?

in reply to Fabio

@Fabio No, it returns a new array with all the non-empty values in the input array. It doesn't empty the array, unless there are no non-empty values in it.
in reply to Fabio

@Fabio Definitely something that's too clever for its own good. You can definitely see the Perl inspiration at work here: "How about we shorten the syntax so that it's extremely counter-intuitive but pretty nifty once you figure it out".

Questo sito utilizza cookie per riconosce gli utenti loggati e quelli che tornano a visitare. Proseguendo la navigazione su questo sito, accetti l'utilizzo di questi cookie.