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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:39:36+00:00 2026-06-14T10:39:36+00:00

I have an array named results_array: var_dump($results_array): 0 => php,mysql,jquery,ruby,html,css,lamp 1 => mouse,keyboard,laptop,pad 2

  • 0

I have an array named results_array:

var_dump($results_array):
0 => php,mysql,jquery,ruby,html,css,lamp
1 => mouse,keyboard,laptop,pad
2 => table,sofa,caption
3 => control,television,control television,television control

and I have a $q which stands for query, I want to search in the $results_array and remove the items which has nothing to do with the query, so if I set $q=a then results array should be this:

0 => lamp
1 => keyboard,laptop,pad
3 => table,sofa,caption
4 => empty

now, I want to put the above results in each index of the results_array, at the end results_array should be:

0 => lamp
1 => keyboard
2 => laptop
3 => pad
4 => table
5 => sofa
6 => caption

my code is:

foreach($results_array as &$row) {
            $row = explode(',', $row);
        }
        unset($row);
        $results_array = call_user_func_array('array_merge_recursive', $results_array);

        foreach ($array as $k => $v) {
            if(strpos($v, 'a') === false) unset($array[$k]);
        }
        $results_array = array_values($results_array);

this exactly does what I need, now I set my $q = ‘tele co’, now after applying the above code set $ = ‘tele co’, it returns emtpy, but it should not because in:

3 => control,television,control television,television control

‘control television,television control’ should returned, but it’s not, so I change my code to:

foreach($results_array as &$row) {
            $row = explode(',', $row);
        }
        unset($row);
        $results_array = call_user_func_array('array_merge_recursive', $results_array);
// HERE IS CHANGED ****
        $q = preg_split('/\s+/', trim($q));
        foreach ($results_array as $key => $value) {
            foreach ($q as $query) {
                if (stripos($value, $query) === false) {
                    unset($results_array[$key]);
                    break;
                }
            }
        }
// ****
        $results_array = array_values($results_array);

it’s still not working, by passing $q = ‘tele co’ I need that ‘television control’ and ‘control television’ return, because they both got ‘tele’ AND ‘co’ which is in $q

I appreciate any kind of help

  • 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-14T10:39:38+00:00Added an answer on June 14, 2026 at 10:39 am

    Assuming:

    $q = 'a c';
    $results_array = array(
        'php,mysql,jquery,ruby,html,css,lamp',
        'mouse,keyboard,laptop,pad',
        'table,sofa,caption',
        'control,television,control television,television control'
    );
    

    Solution:

    $result = array_map(function ($element) use ($q) {
        $words = explode(',', $element);
        return array_filter($words, function ($word) use ($q) {
            $qwords = explode(' ', $q);
            return count(array_filter($qwords, function ($qword) use ($word) {
                return strpos($word, $qword) !== false;
            })) > 0;
        });
    }, $results_array);
    

    Output print_r($result);:

    Array
    (
        [0] => Array
            (
                [5] => css
                [6] => lamp
            )
    
        [1] => Array
            (
                [1] => keyboard
                [2] => laptop
                [3] => pad
            )
    
        [2] => Array
            (
                [0] => table
                [1] => sofa
                [2] => caption
            )
    
        [3] => Array
            (
                [0] => control
                [2] => control television
                [3] => television control
            )
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array list named newSymptomList which contains a list of Symptom id's
I have mutable string array named arrayout. It is having 3 element .Now I
In my Values folder for my project, I have a string array named currency_avatar.
I have a string array in C named args[] - now how can I
I have an array which contains sets of three similar named items; however, sometimes
i have printed out the contents of an array/object (named 'document') with print_r. it
I have an array generated by PHP array( array( 'name'=>'node1', 'id' => '4' ),
i have this code on the server side: <?php header('Content-Type: text/html; charset=utf-8'); require ../general.variables.php;
For eg I have this code on the main page. <?php session_start(); $_SESSION['order']=array(); ?>
Is there a limit on a value string in php Associative array? I have

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.