Is there an in-built function in PHP that allows me to select array keys that are not one(s) I have specified -
consider array
$my_array("key1"=>"value1", "key2"=>"value2", "key3"=>"value3")
does php have function in can pass in key1 , returns key2 , key3. assuming key1 same key2 , key3 can change time time.
$my_array("key1"=>"value1", "key2"=>"value2", "key3"=>"value3"); $result = the_function_i_want("key1"); print_r($result);
expected output
array ( [key2] => value2 [key3] => value3 )
if wish compare keys use following;
$array1 = array("a" => "green", "red", "blue", "red"); $array2 = array("a" => "green"); function key_diff($array1, $array2){ foreach ($array2 $skey => $value) { if(isset( $array1[$skey] ) ) unset($array1[$skey]); } return $array1; } var_dump(key_diff($array1, $array2)); exit;
if wish compare values can use array_diff() taken php manual
<?php $array1 = array("a" => "green", "red", "blue", "red"); $array2 = array("b" => "green", "yellow", "red"); $result = array_diff($array1, $array2); print_r($result); ?>
multiple occurrences in $array1 treated same way. output :
array ( [1] => blue )
Comments
Post a Comment