note 77750 added to function.array-search

From: Date: Tue, 11 Sep 2007 22:09:44 +0000
Subject: note 77750 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-130385@lists.php.net to get a copy of this message
A variation of previous searches that returns an array of keys that match the given value: <?php function array_ksearch($array, $str) { $result = array(); for($i = 0; $i < count($array); next($array), $i++) if(strtolower(current($array)) == strtolower($str)) array_push($result, key($array); return $result; } ?> Usage would be as follows: <?php $testArray = array('one' => 'test1', 'two' => 'test2', 'three' => 'test1', 'four' => 'test2', 'five' => 'test1'); print_r(array_ksearch($testArray, 'test1')); ?> ---- Server IP: 208.69.120.35 Probable Submitter: 12.104.244.6 ---- Manual Page -- http://www.php.net/manual/en/function.array-search.php Edit -- https://master.php.net/note/edit/77750 Del: integrated -- https://master.php.net/note/delete/77750/integrated Del: useless -- https://master.php.net/note/delete/77750/useless Del: bad code -- https://master.php.net/note/delete/77750/bad+code Del: spam -- https://master.php.net/note/delete/77750/spam Del: non-english -- https://master.php.net/note/delete/77750/non-english Del: in docs -- https://master.php.net/note/delete/77750/in+docs Del: other reasons-- https://master.php.net/note/delete/77750 Reject -- https://master.php.net/note/reject/77750 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#130385) next »