$v ) { if ( $v == $val ) { array_splice( $array, $i, 1 ); return $i; } } return false; } /** * Removes the given value from the given associative array. * * Returns either FALSE if the value was not found in the array * or the key at which the value was found and removed. * * $array2 = array( 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4 ); * assert( array_remove_assoc( 1, $array2 ) == 'a' ); * assert( array( 'b' => 2, 'c' => 3, 'd' => 4 ) == $array2 ); * * @param mixed $val The value to remove * @param array $array The associative array from which to remove the value * @returns FALSE or the index at which the value was found * @author Dimitry Zolotaryov, http://webit.ca */ function array_remove_assoc( $val, &$array ) { foreach ( $array as $key => $value ) { if ( $value == $val ) { unset( $array[ $key ] ); return $key; } } return false; }