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 5973007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:44:22+00:00 2026-05-22T20:44:22+00:00

I am using array_filter to do something like this: function endswithy($value) { return (substr($value,

  • 0

I am using array_filter to do something like this:

function endswithy($value) {
    return (substr($value, -1) == 'y');
}

$people = array("Johnny", "Timmy", "Bobby", "Sam", "Tammy", "Danny", "Joe");
$withy = array_filter($people, "endswithy");
var_dump($withy);

BUT with the more option in filter for example

$people = array(
             "Johnny"=>array("year"=>1989, "job"=>"prof"),
             "Timmy"=>array("year"=>1989,  "job"=>"std"),
             "Bobby"=>array("year"=>1988),
             "Sam"=>array("year"=>1983),
             "Tammy"=>array("year"=>1985),
             "Danny"=>array("year"=>1983),
             "Joe"=>array("year"=>1989,"job"=>"prof"));

OR

$people = array(
             array("name"=>"Johnny","year"=>1989, "job"=>"prof"),
             array("name"=>"Timmy","year"=>1989,  "job"=>"std"),
             array("name"=>"Bobby""year"=>1988),
             array("name"=>"Sam","year"=>1983),
             array("name"=>"Tammy","year"=>1985),
             array("name"="Danny","year"=>1983),
             array("name"="Joe","year"=>1989,"job"=>"prof"));

How Can I got the only this people (endwith y and year=1989 and job=prof) ,Can I use array_filter?
or any build-in function to do this?

$people = array(
                 "Johnny"=>array("year"=>1989, "job"=>"prof")
  );

OR

$people = array(
                 array("name="Johnny","year"=>1989, "job"=>"prof")
  );
  • 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-22T20:44:23+00:00Added an answer on May 22, 2026 at 8:44 pm

    Either use foreach with your current array’s structure:

    $people = array(
        "Johnny" => array("year" => 1989, "job" => "prof"),
        "Timmy"  => array("year" => 1989, "job" => "std"),
        "Bobby"  => array("year" => 1988),
        "Sam"    => array("year" => 1983),
        "Tammy"  => array("year" => 1985),
        "Danny"  => array("year" => 1983),
        "Joe"    => array("year" => 1989, "job" => "prof"),
    );
    
    foreach ( $people as $name => $info ) {
        if ( substr($name, -1) !== 'y' || $info['year'] != 1989 ) {
            unset($people[$name]);
        }
    }
    
    print_r($people);
    
    // output:
    Array
    (
        [Johnny] => Array
            (
                [year] => 1989
                [job] => prof
            )
        [Timmy] => Array
            (
                [year] => 1989
                [job] => std
            )
    )
    

    Or convert your array so that name is value of inner array:

    $people = array(
        array('name' => 'Johnny', 'year' => 1989, 'job' => 'prof'),
        array('name' => 'Timmy' , 'year' => 1989, 'job' => 'std'),
        array('name' => 'Bobby' , 'year' => 1988),
        array('name' => 'Sam'   , 'year' => 1983),
        array('name' => 'Tammy' , 'year' => 1985),
        array('name' => 'Danny' , 'year' => 1983),
        array('name' => 'Joe'   , 'year' => 1989, 'job' => 'prof'),
    );
    
    function filter($item) {
        return substr($item['name'], -1) === 'y' && $item['year'] == 1989;
    }
    
    $filteredPeople = array_filter($people, 'filter');
    
    print_r($filteredPeople);
    
    // output:
    Array
    (
        [0] => Array
            (
                [name] => Johnny
                [year] => 1989
                [job] => prof
            )
        [1] => Array
            (
                [name] => Timmy
                [year] => 1989
                [job] => std
            )
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to filter an array of items by using the map() function.
How would I convert the following to a VB.NET predicate using Array.Find? Private Function
how can i filter an array using key value combination. let array is a=>1
Basically I'd like to do something like this: $arr = [1, 2, 3, 4,
I'm trying to parse strings that represent source code, something like this: [code lang=html]
i have an array structured like: $something = array( 0 => array( 'label' =>
I couldn't quite find something like this, hence the question. I have a page\blarg
I have an IEnumerable<DirectoryInfo> that I want to filter down using an array of
After using array_unique , an array without the duplicate values is removed. However, it
I need to create an array of arrays. I have been using array_map(null,$a,$b,$c) to

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.