...

View Full Version : Removing a value from an associative array



NancyJ
11-24-2007, 12:55 AM
Is there any way I can remove a key/value pair from an associative array, given the key?

CFMaBiSmAd
11-24-2007, 01:02 AM
unset() -


$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>";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum