<?php
function flat_map(callable $callback, array $collection) {
return array_merge([], ...array_map($callback, $collection));
};
var_dump(
array_map(function ($el) { return str_split($el); }, ["two birds", "three green peas"])
);
var_dump(
flat_map(function ($el) { return str_split($el); }, ["two birds", "three green peas"])
);
var_dump(
flat_map(function ($el) { return str_split($el); }, [])
);
- Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
- array(2) {
[0]=>
array(9) {
[0]=>
string(1) "t"
[1]=>
string(1) "w"
[2]=>
string(1) "o"
[3]=>
string(1) " "
[4]=>
string(1) "b"
[5]=>
string(1) "i"
[6]=>
string(1) "r"
[7]=>
string(1) "d"
[8]=>
string(1) "s"
}
[1]=>
array(16) {
[0]=>
string(1) "t"
[1]=>
string(1) "h"
[2]=>
string(1) "r"
[3]=>
string(1) "e"
[4]=>
string(1) "e"
[5]=>
string(1) " "
[6]=>
string(1) "g"
[7]=>
string(1) "r"
[8]=>
string(1) "e"
[9]=>
string(1) "e"
[10]=>
string(1) "n"
[11]=>
string(1) " "
[12]=>
string(1) "p"
[13]=>
string(1) "e"
[14]=>
string(1) "a"
[15]=>
string(1) "s"
}
}
array(25) {
[0]=>
string(1) "t"
[1]=>
string(1) "w"
[2]=>
string(1) "o"
[3]=>
string(1) " "
[4]=>
string(1) "b"
[5]=>
string(1) "i"
[6]=>
string(1) "r"
[7]=>
string(1) "d"
[8]=>
string(1) "s"
[9]=>
string(1) "t"
[10]=>
string(1) "h"
[11]=>
string(1) "r"
[12]=>
string(1) "e"
[13]=>
string(1) "e"
[14]=>
string(1) " "
[15]=>
string(1) "g"
[16]=>
string(1) "r"
[17]=>
string(1) "e"
[18]=>
string(1) "e"
[19]=>
string(1) "n"
[20]=>
string(1) " "
[21]=>
string(1) "p"
[22]=>
string(1) "e"
[23]=>
string(1) "a"
[24]=>
string(1) "s"
}
array(0) {
}
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
array(2) {
[0]=>
array(9) {
[0]=>
string(1) "t"
[1]=>
string(1) "w"
[2]=>
string(1) "o"
[3]=>
string(1) " "
[4]=>
string(1) "b"
[5]=>
string(1) "i"
[6]=>
string(1) "r"
[7]=>
string(1) "d"
[8]=>
string(1) "s"
}
[1]=>
array(16) {
[0]=>
string(1) "t"
[1]=>
string(1) "h"
[2]=>
string(1) "r"
[3]=>
string(1) "e"
[4]=>
string(1) "e"
[5]=>
string(1) " "
[6]=>
string(1) "g"
[7]=>
string(1) "r"
[8]=>
string(1) "e"
[9]=>
string(1) "e"
[10]=>
string(1) "n"
[11]=>
string(1) " "
[12]=>
string(1) "p"
[13]=>
string(1) "e"
[14]=>
string(1) "a"
[15]=>
string(1) "s"
}
}
array(25) {
[0]=>
string(1) "t"
[1]=>
string(1) "w"
[2]=>
string(1) "o"
[3]=>
string(1) " "
[4]=>
string(1) "b"
[5]=>
string(1) "i"
[6]=>
string(1) "r"
[7]=>
string(1) "d"
[8]=>
string(1) "s"
[9]=>
string(1) "t"
[10]=>
string(1) "h"
[11]=>
string(1) "r"
[12]=>
string(1) "e"
[13]=>
string(1) "e"
[14]=>
string(1) " "
[15]=>
string(1) "g"
[16]=>
string(1) "r"
[17]=>
string(1) "e"
[18]=>
string(1) "e"
[19]=>
string(1) "n"
[20]=>
string(1) " "
[21]=>
string(1) "p"
[22]=>
string(1) "e"
[23]=>
string(1) "a"
[24]=>
string(1) "s"
}
array(0) {
}
- Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38
- Parse error: syntax error, unexpected '.' in /in/qQNTv on line 5
Process exited with code 255. - Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
- Parse error: syntax error, unexpected '[', expecting ')' in /in/qQNTv on line 5
Process exited with code 255. - Output for 5.0.0 - 5.0.5
- Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/qQNTv on line 4
Process exited with code 255. - Output for 4.4.2 - 4.4.9
- Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/qQNTv on line 4
Process exited with code 255. - Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
- Parse error: parse error, unexpected T_STRING, expecting ')' in /in/qQNTv on line 4
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error, expecting `')'' in /in/qQNTv on line 4
Process exited with code 255.
preferences:
214.4 ms | 401 KiB | 468 Q