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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:06:24+00:00 2026-06-06T05:06:24+00:00

I have the following array: Array ( [0] => BCD [1] => ACE [2]

  • 0

I have the following array:

Array
(
    [0] => BCD
    [1] => ACE
    [2] => AHP
    [3] => BGH
    [4] => ART
    [5] => COT
    [6] => ARG
    [7] => BGT
)

I need to match all elements whose first letter is in the following array:

Array
(
    [0] => B
    [1] => A
)

to get:

Array
(
    [0] => ACE
    [1] => AHP
    [2] => BGH
    [3] => ART
    [4] => ARG
    [5] => BGT
)

Short of looping through the whole array, how do I do this in PHP? Is there a built-in PHP array function for this or a combination of so? The order does not matter for both keys and values of the resulting array. Thanks much.

  • 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-06-06T05:06:26+00:00Added an answer on June 6, 2026 at 5:06 am

    You can use array_filter for these operations:

    $array = array('CBD', 'NHN', 'NHP', 'WHC', 'NND', 'CQN', 'WST', 'WVT');
    
    $whitelist = array('W', 'N');
    
    $filtered = array_filter($array, function($val) use ($whitelist) {
      // check if first letter is in the whitelist array
      if (in_array($val{0}, $whitelist)) {
        return $val;
      }
      return false;
    });
    

    Output:

    Array
    (
        [1] => NHN
        [2] => NHP
        [3] => WHC
        [4] => NND
        [6] => WST
        [7] => WVT
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following array, that I need to operate by hand on bitmaps. const
I have the following array and I want to group all the users of
I have the following array that I need to have sorted from highest score
I have the following array. I need to sort this array by the nested
I have the following array that I need to recursively loop through and remove
I have following array: var events = [ {id : 1, start : 100,
I have the following array: items = array( 'note' => array(), 'text' => array(),
I have the following array: open_emails = [[2012-04-21, 5], [2012-04-20, 1], [2012-04-22, 4]]; But
I have the following array structure: 0 => array 'all_sessions_available' => boolean true 'all_sessions_unavailable'
I have the following array ($arrayres) (example data) Array ( [0] => Array (

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.