I have an array like this:
[
[
'key1' => 'hello im a text',
'key2' => true,
'key3' => '><><',
],
[
[
'key1' => 'hello another text',
'key2' => 'im a text too',
'key3' => false,
],
[
'key1' = ')(&#',
],
],
[
'key1' => 'and so on',
]
]
How can I extract values which with a string length of 5 or more and populate a flat array?
Desired result:
[
1 => 'hello im a text',
2 => 'hello another text',
3 => 'im a text too',
4 => 'and so on',
]
Heres what I’ve done:
$found = array();
function search_text($item, $key)
{
global $found;
if (strlen($item) > 5)
{
$found[] = $item;
}
}
array_walk_recursive($array, 'search_text');
var_dump($found);
but somehow it doesn’t work.
Try something similar to this:
My note: I haven’t tested this, if there’s bugs, please tell me and I’ll try to fix them.