@ 2014-09-07T06:31:28Z <?php
$arr = array( array("item_data"=>array(1,2,3),"type"=>a), array("item_data"=>array(4,5,6)), array("item_data"=>array(7,8,9)) );
var_dump($arr);
function merge($prev, $now) {
return array_merge($prev, $now['item_data']);
}
$res = array_reduce($arr, "merge", array());
print_r($res);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.27 , 8.2.0 - 8.2.17 , 8.3.0 - 8.3.4 Fatal error: Uncaught Error: Undefined constant "a" in /in/Hu0at:3
Stack trace:
#0 {main}
thrown in /in/Hu0at on line 3
Process exited with code 255 . Output for 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 Warning: Use of undefined constant a - assumed 'a' (this will throw an Error in a future version of PHP) in /in/Hu0at on line 3
array(3) {
[0]=>
array(2) {
["item_data"]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
["type"]=>
string(1) "a"
}
[1]=>
array(1) {
["item_data"]=>
array(3) {
[0]=>
int(4)
[1]=>
int(5)
[2]=>
int(6)
}
}
[2]=>
array(1) {
["item_data"]=>
array(3) {
[0]=>
int(7)
[1]=>
int(8)
[2]=>
int(9)
}
}
}
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 7
[7] => 8
[8] => 9
)
Output for 4.3.0 - 4.3.9 , 5.0.0 - 5.0.2 , 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.24 - 5.5.35 , 5.6.7 - 5.6.28 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.33 Notice: Use of undefined constant a - assumed 'a' in /in/Hu0at on line 3
array(3) {
[0]=>
array(2) {
["item_data"]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
["type"]=>
string(1) "a"
}
[1]=>
array(1) {
["item_data"]=>
array(3) {
[0]=>
int(4)
[1]=>
int(5)
[2]=>
int(6)
}
}
[2]=>
array(1) {
["item_data"]=>
array(3) {
[0]=>
int(7)
[1]=>
int(8)
[2]=>
int(9)
}
}
}
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 7
[7] => 8
[8] => 9
)
Output for 5.0.3 - 5.0.5 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 Notice: Use of undefined constant a - assumed 'a' in /in/Hu0at on line 3
array(3) {
[0]=>
array(2) {
["item_data"]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
["type"]=>
string(1) "a"
}
[1]=>
array(1) {
["item_data"]=>
array(3) {
[0]=>
int(4)
[1]=>
int(5)
[2]=>
int(6)
}
}
[2]=>
array(1) {
["item_data"]=>
array(3) {
[0]=>
int(7)
[1]=>
int(8)
[2]=>
int(9)
}
}
}
Warning: array_merge(): Argument #1 is not an array in /in/Hu0at on line 6
Warning: array_merge(): Argument #1 is not an array in /in/Hu0at on line 6
Warning: array_merge(): Argument #1 is not an array in /in/Hu0at on line 6
Output for 4.3.10 - 4.3.11 , 4.4.0 - 4.4.9 Notice: Use of undefined constant a - assumed 'a' in /in/Hu0at on line 3
array(3) {
[0]=>
array(2) {
["item_data"]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
["type"]=>
string(1) "a"
}
[1]=>
array(1) {
["item_data"]=>
array(3) {
[0]=>
int(4)
[1]=>
int(5)
[2]=>
int(6)
}
}
[2]=>
array(1) {
["item_data"]=>
array(3) {
[0]=>
int(7)
[1]=>
int(8)
[2]=>
int(9)
}
}
}
Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
[4] => 4
[5] => 5
[6] => 6
[7] => 7
[8] => 8
[9] => 9
)
preferences:dark mode live preview
236.63 ms | 403 KiB | 339 Q