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

The Archive Base Latest Questions

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

See this: $q = ‘blah’; for($k = 0; $k < count($results_array); $k++){ $results_array_ .

  • 0

See this:

        $q = 'blah';
        for($k = 0; $k < count($results_array); $k++){
            $results_array_ . $k = explode(',', $results_array[$k]);
            foreach($results_array_ . $k as $key => $value){
                if (stripos($value, $q) === false) {
                unset($results_array_ . $k[$key]);
                break;
                }
            }
        }

On line 3 I’m simply using “$results_array_ . $k” and it’s working just fine, but on line 6 I’m getting PHP parse errors on “unset($results_array_ . $k[$key])”, why is this happening?

I appreciate anykind of help


Why I’m doing it:

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

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

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
  • 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-14T07:16:13+00:00Added an answer on June 14, 2026 at 7:16 am

    Answer to original question

    unset expects its argument to be a direct reference to a value, e.g. $var or $array['key']. If you want to dynamically create the argument based on other values, you ‘ll have to use variable variable syntax:

    unset(${$results_array_ . $k[$key]});
    

    This will get rid of the warning, but it still won’t make the code work because it’s fundamentally flawed. Line 3 which you mention reads:

    $results_array_ . $k = explode(',', $results_array[$k]);
    

    What this does is explode an array into $k and then concatenate $results_array_ with $k and… throw away the result. You could just as easily have written

    $k = explode(',', $results_array[$k]);
    

    and it would work the same (except possibly not giving an E_NOTICE that $_results_array_ does not exist).

    So, it seems that you have a misunderstanding of how some PHP fundamentals work. It would be best if you asked another question that explains what you are trying to do, in order to determine what would be a good way of doing it.

    Answer to current question

    Let’s take the steps one at a time:

    1. Take the array of strings and turn each string into an array with explode, making an array of arrays. You can do this with array_map or a simple foreach.
    2. “Flatten” the array of arrays into one big array. You can do this with array_merge or array_merge_recursive (the details will be a bit different, the idea is the same).
    3. Search the flattened array and filter out uninteresting elements with array_filter.
    4. If necessary, reindex the filtered array so that it has consecutive numeric keys with array_values.

    Here’s code that does this, albeit a little differently (I am doing steps 1 and 2 at the same time in the first line using array_reduce):

    $array = (...);
    $array = array_reduce($array, function(&$result, $item) {
        return array_merge($result, explode(',', $item));
    }, array());
    $array = array_filter($array, function($item) use ($string) { 
        return strpos($item, $string) !== false;
    });
    $result = array_values($array);
    

    A version that does the same without using fancy functions:

    // Step 1
    foreach($array as &$row) {
        $row = explode(',', $row);
    }
    unset($row);
    
    // Step 2
    $array = call_user_func_array('array_merge_recursive', $array);
    
    // Step 3
    foreach ($array as $k => $v) {
        if(strpos($v, 'a') === false) unset($array[$k]);
    }
    
    // Step 4
    $array = array_values($array);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

see this demo from jquery ui you have to hold down the Ctrl key
See this code: http://codepad.org/s8XnQJPN function getvalues($delete = false) { static $x; if($delete) { echo
See this simple piece of code in PHP: //Documentation: //memcache_set ( string $key ,
I see this in code sometimes: struct S { int count; // length of
See this: var x = function() { if(true) { return false; } return true;
See this question. How to show popup message like in stackoverflow I am trying
see this fiddle . This upon running gives an error in console. I'm currently
See this code: TicketStoreService fakeTicketStoreService = MockRepository.GenerateMock<TicketStoreService>(); fakeTicketStoreService.Expect(service => service.DoSomething(Arg.Is(new Guid())) .Return(new Guid()); fakeTicketStoreService.DoSomething(Arg.Is(new
See this code: var jsonString = '{id:714341252076979033,type:FUZZY}'; var jsonParsed = JSON.parse(jsonString); console.log(jsonString, jsonParsed); When
See this Image below http://i46.tinypic.com/2pt6jkn.jpg This is report in SSRS as shown when it

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.