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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:59:01+00:00 2026-06-16T07:59:01+00:00

I am trying to search for qualifying entries in a multidimensional array and return

  • 0

I am trying to search for qualifying entries in a multidimensional array and return one or more data sets as flattened, associative subarrays.

Sample input:

[
    [
        'name' => 'Dick Jansen',
        'matchedMovie' => [
            [
                'nameMovie' => 'Saw',
                'genre' => 'Horror',
                'patheMovie' => 'Texas Chainsaw 3D',
                'patheMovieGenre' => 'Horror',
                'score' => '100.00',
            ]
        ]
    ],
    [
        'name' => 'Jim Scott',
        'matchedMovie' => [
            [
                'nameMovie' => 'Shooter',
                'genre' => 'Action, Thriller',
                'patheMovie' => 'The Shining',
                'patheMovieGenre' => 'Horror, Suspense/Thriller',
                'score' => '52.38',
            ],                
            [
                'nameMovie' => 'Resident Evil Movie',
                'genre' => 'Action/Horror',
                'patheMovie' => 'Texas Chainsaw 3D',
                'patheMovieGenre' => 'Horror',
                'score' => '63.16',
            ]
        ]
    ]
]

I want to search on the patheMovie values (like ‘The Shining’) and get the parent array’s name plus only the matchedMovie array with the matched patheMovie value.

My code:

$search = 'Texas Chainsaw 3D';

$sorted = false;
foreach ($sorted as $n => $c)
    if (in_array($search, $c)) {
        $cluster = $n;
        break;
    }

If I search for The Shining, the result should be:

array (
  0 => 
  array (
    'name' => 'Jim Scott',
    'nameMovie' => 'Shooter',
    'genre' => 'Action, Thriller',
    'patheMovie' => 'The Shining',
    'patheMovieGenre' => 'Horror, Suspense/Thriller',
    'score' => '52.38',
  ),
)

If I search for Texas Chainsaw 3D, then the result should be:

array (
  0 => 
  array (
    'name' => 'Dick Jansen',
    'nameMovie' => 'Saw',
    'genre' => 'Horror',
    'patheMovie' => 'Texas Chainsaw 3D',
    'patheMovieGenre' => 'Horror',
    'score' => '100.00',
  ),
  1 => 
  array (
    'name' => 'Jim Scott',
    'nameMovie' => 'Resident Evil Movie',
    'genre' => 'Action/Horror',
    'patheMovie' => 'Texas Chainsaw 3D',
    'patheMovieGenre' => 'Horror',
    'score' => '63.16',
  ),
)
  • 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-16T07:59:02+00:00Added an answer on June 16, 2026 at 7:59 am

    This solution will depend into two conjugated loops.

    <?php
    function searchIt($arr, $searchItem){
    $result = array();
    $resultIndex = 0;
    for ($i =0; $i < count($arr); $i++){
     for ($j = 0; $j < count($arr[$i]['matchedMovie']); $j++){
      if ($arr[$i]['matchedMovie'][$j]['patheMovie'] == $searchItem){
       $result[$resultIndex]['name'] = $arr[$i]['name'];
        foreach ($arr[$i]['matchedMovie'][$j] as $key => $value){
         $result[$resultIndex][$key] = $value;
       }
        $resultIndex++;
      }
     } 
    }
    return $result;
    }
    ?>
    

    phpfiddle demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to search for a more elegant/overall solution to our common/basic data export tasks
I am trying to search a MongoDB database filtering on a specific data item.
I am trying to search if char from alpabet array is equal to the
I am trying to search through a Load Balancer config and extract some data.
I'm trying to search an array for lines that contain $inbucket[0]. Some of my
I'm trying to search the SRC of a set of images then return all
I'm trying to search the SRC of a set of images then return all
i am trying search data in xml file. if found, it will popup MessageBox
I am trying to search or get the xml elements of one file based
Im trying to search a array and navigate to the next and previous values

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.