Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts

    Removing a value from an associative array

    Is there any way I can remove a key/value pair from an associative array, given the key?

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,091
    Thanks
    2
    Thanked 322 Times in 314 Posts
    unset() -

    PHP Code:
    $arr['keep_this_1'] = 'I want 1';
    $arr['remove_this'] = 'this will be gone';
    $arr['keep_this_2'] = 'I want 2';

    echo 
    "<pre>";
    print_r($arr);
    echo 
    "</pre>";
    echo 
    "<br />";

    $key 'remove_this';
    unset(
    $arr[$key]);

    echo 
    "<pre>";
    print_r($arr);
    echo 
    "</pre>"
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    NancyJ (11-24-2007)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •