note 94381 added to ref.array

From: Date: Sun, 01 Nov 2009 03:24:34 +0000
Subject: note 94381 added to ref.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-162316@lists.php.net to get a copy of this message
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. ---- Server IP: 203.121.145.123 Probable Submitter: 117.47.45.249 ---- Manual Page -- http://www.php.net/manual/en/ref.array.php Edit -- https://master.php.net/note/edit/94381 Del: integrated -- https://master.php.net/note/delete/94381/integrated Del: useless -- https://master.php.net/note/delete/94381/useless Del: bad code -- https://master.php.net/note/delete/94381/bad+code Del: spam -- https://master.php.net/note/delete/94381/spam Del: non-english -- https://master.php.net/note/delete/94381/non-english Del: in docs -- https://master.php.net/note/delete/94381/in+docs Del: other reasons-- https://master.php.net/note/delete/94381 Reject -- https://master.php.net/note/reject/94381 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#162316) next »