Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7421223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:22:21+00:00 2026-05-29T08:22:21+00:00

I’d like to sort an array such that i can extract some users from

  • 0

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'=>'bb@bb.com',
                  'id'=>'1');

$users['2'] = array('name'=>'jerry jones',
               'email'=> 'jj@jj.com',
                  'id'=>'2' );

$users['3'] = array('name'=>'sue smith',
               'email'=>'ss@ss.com',
                  'id'=>'3' );

$users['4'] = array('name'=>'zach zed',
               'email'=>'zz@zz.com',
                  'id'=>'4' );

function sort_jerry_and_sue($users)
{
    $j_and_s=array('jj@jj.com', 'ss@ss.com');
    $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] => bb@bb.com [id] => 1 )    [1] => Array ( [name] => zach zed [email] => zz@zz.com [id] => 4 ))
print_r($js);
// this is what i'd like it to print=> $js = Array ([0] => Array ( [name] => jerry jones [email] => jj@jj.com [id] => 2 ) [1]   => Array ( [name] => sue smith [email] => ss@ss.com [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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:22:21+00:00Added an answer on May 29, 2026 at 8:22 am

    I think you are going about this the wrong way. array_filter is like a array_map call that takes as its second argument a callable that will return a boolean determining whether or not the value exists in the filtered set. The argument to the sort_jerry_and_sue function will be each user element of the $users array, one by one.

    By returning false if the user has one of the predefined email addresses, you essentially filer them out of the resultant array.

    Once you have one set of a boolean filtered set, you get the compliment by doing an array_diff_assoc to get the difference.

    <?php
    
    
    class EmailFilter {
    
      private $emails = array();
    
      public function __construct(array $emails) {
        $this->emails = $emails;
      }
    
      public function filter_users($user) {
        return in_array($user['email'], $this->emails);
      }
    
    }
    
    $users['1'] = array('name'=>'bob barker', 'email'=>'bb@bb.com', 'id'=>'1');
    $users['2'] = array('name'=>'jerry jones', 'email'=> 'jj@jj.com', 'id'=>'2' );
    $users['3'] = array('name'=>'sue smith', 'email'=>'ss@ss.com', 'id'=>'3' );
    $users['4'] = array('name'=>'zach zed', 'email'=>'zz@zz.com', 'id'=>'4' );
    
    $filter_emails = array('jj@jj.com', 'ss@ss.com');
    $not_js = array_filter($users, array(new EmailFilter($filter_emails), 'filter_users'));
    $js = array_diff_assoc($users, $not_js);
    
    // this is what i'd like it to print=> $not_js = Array ([0] => Array ( [name] => bob barker [email] => bb@bb.com [id] => 1 )    [1] => Array ( [name] => zach zed [email] => zz@zz.com [id] => 4 ))
    print_r($not_js);
    // this is what i'd like it to print=> $js = Array ([0] => Array ( [name] => jerry jones [email] => jj@jj.com [id] => 2 ) [1]   => Array ( [name] => sue smith [email] => ss@ss.com [id] => 3 ))
    print_r($js);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.