Hola tengo un array con cierta estructura donde quiero filtrar solo los que contienen 'survey78399' , pero en algunos casos no logro hacerla funcionar.
la estructura del array:
Código PHP:
Array
(
[0] => Array
(
[email] => john.doe@sendgrid.com
[timestamp] => 1337966815
[category] => survey78399
[event] => open
)
[2] => Array
(
[email] => juanito@email.com
[timestamp] => 1337966855
[category] => Array
(
[0] => survey78399
[1] => transactional
)
[event] => spam
)
[3] => Array
(
[email] => jajjaa@test.com
[timestamp] => 1337966899
[category] => Array
(
[0] => survey78399
[1] => transactional
)
[event] => open
)
[4] => Array
(
[sg_event_id] => sendgrid_internal_event_id
[sg_message_id] => sendgrid_internal_message_id
[ip] => 255.255.255.255
[useragent] => Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53
[event] => click
[email] => email@example.com
[timestamp] => 1249948800
[url] => http://yourdomain.com/blog/news.html
[url_offset] => Array
(
[index] => 0
[type] => html
)
[unique_arg_key] => unique_arg_value
[category] => Array
(
[0] => category1
[1] => category2
)
[newsletter] => Array
(
[newsletter_user_list_id] => 10557865
[newsletter_id] => 1943530
[newsletter_send_id] => 2308608
)
[asm_group_id] => 1
)
)
mi codigo :
Código PHP:
function debug($valor)
{
echo "<pre>";
print_r($valor);
echo "</pre>";
exit;
}
$search = 'survey78399';
$callback = function($item) use (&$callback, &$search) {
if (is_array($item)) {
return array_filter($item, $callback);
}else {
return $item == $search;
}
};
$filtered = array_filter($arr, $callback);
debug($filtered);
Saludos