Wait

php array_remove()

A missing php function: array_remove(). This function will remove the key/value of all occurances of the value given in the function. Specify the array and also the key you want to remove from the array. The array_remove function will then remove all key/value pairs from the array.

Here is the array_remove function.

/* -----------------------------------------------------------------------------------
    FUNCTION :      array_remove()

    DESCRIPTION :     This function is not multideminsional safe. Enter the array and the
                    value you want removed.  It will remove the key/value of all occurances
                    of that value.
------------------------------------------------------------------------------------*/
function array_remove($array, $value) {
    $new_arr = array_keys($array,$value); // get the keys that contain this value
    $new_arr = array_flip($new_arr); // Exchanges all keys with their associated values
    $new_arr = array_diff_key($array,$new_arr); // Returns an array containing all the entries from array1 that are not present in the second array.
    return $new_arr; //the new array with the specified value removed
}

Sample array_remove() Usage


$array = array('first'=>'cars','second'=>'trunks','third'=>'automobiles');
$array = array_remove($array,'cars');
print_r($array);
// will return:
// 'second'=>'trunks','third'=>'automobiles'
Submit a comment

(required) (required, will not be shown) (optional) 2 + 3 =

Valid XHTML 1.0 Strict

Valid XHTML 1.0 Strict

Valid XHTML 1.0 Strict

Valid XHTML 1.0 Strict

Valid XHTML 1.0 Strict

Valid XHTML 1.0 Strict