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

  • Home
  • SEARCH
  • 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 8837495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:44:22+00:00 2026-06-14T09:44:22+00:00

Hey guys im trying to search an array for an value and then remove

  • 0

Hey guys im trying to search an array for an value and then remove it. But im searching with a php variable and that seems to be the problem. So this is what I have so far:

if(isset($_REQUEST['Admin'])){
    $arr = array('HAUGMA1', 'sdasd', 'dasdasda', 'sadasd');
    $key=array_search($_REQUEST['Admin'],$arr);
    if($key!==false) 
        unset($arr[$key]);
    print_r($arr);
}

The $_REQUEST retrieves the value HAUGMA1 but when I print out the array it didn’t remove HAUGMA1 from it. What am I doing wrong? When I’m using this:

$key=array_search('HAUGMA1',$arr); 

It is working.

  • 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-14T09:44:23+00:00Added an answer on June 14, 2026 at 9:44 am

    I think the problem is in relation to the value that is coming from the $_REQUEST variable.
    I made the following test to show two questions:

    //Array definition
    $arr = array('HAUGMA1', 'sdasd', 'dasdasda', 'sadasd');
    //Search
    $admin = 'dasdasda';
    
    /* First sample */
    
    $time = microtime();
    
    $arr = array_filter($arr, function($key) use($admin) {
        return $key != $admin;
    });
    
    print_r($arr);
    echo '<br>Execution time: '.(microtime()-$time).'<br>';
    
    /* Second sample */
    
    $time = microtime();
    
    $key = array_search($admin, $arr);
    if($key !== false)
        unset($arr[$key]);
    
    print_r($arr);
    echo '<br>Execution time: '.(microtime()-$time).'<br>';
    

    First: using the array_search has approximately 4x faster than array_filter.

    Second: the way that your script is, the item is removed from the array without problem. Try to debug the value that is coming from the variable $_REQUEST

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

Sidebar

Related Questions

Hey guys I have a weird problem trying to use a global array in
Hey guys, I'm trying to add a textfield.text entry to an array. I want
Hey guys I'm trying to make a basic calculator (polish style) but can't figure
hey guys im trying to save a url link in a html form but
Hey guys I'm trying to work my way through this but am having an
Hey guys i have been trying to make a NIO server/client program. My problem
Hey guys, I'm currently trying to implement a function using C that takes in
Hey guys, I'm trying to select a specific string out of a text, but
Hey guys i am trying to install the dropbox-api onto my suse 11.4 but
Hey guys I am trying to build a database that maps NSStrings to int.

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.