<?php
$items = [
'total' => '5',
'_embedded' => [
'articles' => function() { yield "Article 1"; }
],
'more' => [
'nested' => [
'news' => function() { yield "Article 2"; }
],
],
];
$generators = [];
$count = 0;
array_walk_recursive($items, function (&$item, $key) use (&$count, &$generators)
{
if (is_callable($item)) {
$placeholder = '__placeholder_' . $count . '__';
$generators[$placeholder] = $item;
$item = $placeholder;
++$count;
}
});
var_dump($items);
var_dump($generators);
- Output for 8.4.1 - 8.4.12
- array(3) {
["total"]=>
string(1) "5"
["_embedded"]=>
array(1) {
["articles"]=>
string(17) "__placeholder_0__"
}
["more"]=>
array(1) {
["nested"]=>
array(1) {
["news"]=>
string(17) "__placeholder_1__"
}
}
}
array(2) {
["__placeholder_0__"]=>
object(Closure)#1 (3) {
["name"]=>
string(21) "{closure:/in/tndhO:7}"
["file"]=>
string(9) "/in/tndhO"
["line"]=>
int(7)
}
["__placeholder_1__"]=>
object(Closure)#2 (3) {
["name"]=>
string(22) "{closure:/in/tndhO:11}"
["file"]=>
string(9) "/in/tndhO"
["line"]=>
int(11)
}
}
- Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25
- array(3) {
["total"]=>
string(1) "5"
["_embedded"]=>
array(1) {
["articles"]=>
string(17) "__placeholder_0__"
}
["more"]=>
array(1) {
["nested"]=>
array(1) {
["news"]=>
string(17) "__placeholder_1__"
}
}
}
array(2) {
["__placeholder_0__"]=>
object(Closure)#1 (0) {
}
["__placeholder_1__"]=>
object(Closure)#2 (0) {
}
}
preferences:
113.26 ms | 409 KiB | 5 Q