note 94381 deleted from ref.array by levim
| From: | levim@php.net | Date: | Tue, 06 May 2014 22:06:05 +0000 |
| Subject: | note 94381 deleted from ref.array by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-199457@lists.php.net to get a copy of this message | ||
Note Submitter: shadiadiph at yahoo dot com
----
This is a useful function to remove an array value from an array.
<?php
function rem_array($array,$str){
foreach ($array as $key => $value) {
if ($array[$key] == "$str") unset($array[$key]);
}
return $array;
}
$selected='';
$selected ="three";
$numbers=array();
$numbers=array('one','two','three','four');
print_r($numbers);
// returns Array ( [0] => one [1] => two [2] => three [3] => four )
// now we are going to call the function to see if the number three the $selected number is in the
array $numbers and remove it.
$numbers = rem_array($numbers,$selected);
print_r ($numbers);
// returns Array ( [0] => one [1] => two [3] => four )
?>
I am finding it usefull for drop down lists on forms where you do not want the selected value
duplicated.