- var_dump: documentation ( source)
- array_walk_recursive: documentation ( source)
- is_callable: documentation ( source)
<?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);