I'd like to sort an array such that i can extract some users from a multidimensional array based on one parameter, their email addresses. Ultimately I'd like to have the original array separated as 2 different arrays: one with chose email address (labeled $js
below) and one's not (labeled $not_js
below).
Here's my my code:
<?php
$users['1'] = array('name'=>'bob barker',
'email'=>'[email protected]',
'id'=>'1');
$users['2'] = array('name'=>'jerry jones',
'email'=> '[email protected]',
'id'=>'2' );
$users['3'] = array('name'=>'sue smith',
'email'=>'[email protected]',
'id'=>'3' );
$users['4'] = array('name'=>'zach zed',
'email'=>'[email protected]',
'id'=>'4' );
function sort_jerry_and_sue($users)
{
$j_and_s=array('[email protected]', '[email protected]');
$not_js=array();
foreach($j_and_s as $row=>$js){
if(in_array($js, $users)){
}
else {
array_push($not_js, $users);
}
}
return $not_js;
}
$not_js = array_filter($users, 'sort_jerry_and_sue');
print_r($not_js);
// this is what i'd like it to print=> $not_js = Array ([0] => Array ( [name] => bob barker [email] => [email protected] [id] => 1 ) [1] => Array ( [name] => zach zed [email] => [email protected] [id] => 4 ))
print_r($js);
// this is what i'd like it to print=> $js = Array ([0] => Array ( [name] => jerry jones [email] => [email protected] [id] => 2 ) [1] => Array ( [name] => sue smith [email] => [email protected] [id] => 3 ))
?>
Currently printing $not_js
returns all 4 users and the $js
doesn't print anything so obviously that's not right. Any thoughts would be greatly appreciated!