3 ms·
The caveat I'm aware of with array_filter is that it can leave gaps in the indexes, but having an array like that doesn't break array_map. The output from it wi
by zerocrates 6y ago
The caveat I'm aware of with array_filter is that it can leave gaps in the indexes, but having an array like that doesn't break array_map. The output from it will just have the same index gap as the input.
- TazeTSchnitzel 6y agoYeah, there's nothing magical here: $ php -r 'var_dump([1, 2, 3, 4]);' array(4) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) } $ php -r 'var_dump(array_filter([1, 2, 3, 4], function ($x){return (bool)($x % 2);}));' array(2) { [0]=> int(1) [2]=> int(3) } $ php -r 'var_dump(array_map("strval", array_filter([1, 2, 3, 4], function ($x){return (bool)($x % 2);})));' array(2) { [0]=> string(1) "1" [2]=> string(1) "3" }