note 24227 added to function.in-array
| From: | tom at orbittechservices dot com | Date: | Fri, 09 Aug 2002 23:17:58 +0000 |
| Subject: | note 24227 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-34640@lists.php.net to get a copy of this message | ||
I searched the general mailing list and found that in PHP versions before 4.2.0 needle was not
allowed to be an array.
Here's how I solved it to check if a value is in_array to avoid duplicates;
$myArray = array(array('p', 'h'), array('p', 'r'));
$newValue = "q";
$newInsert = array('p','q');
$itBeInThere = 0;
foreach ($myArray as $currentValue) {
if (in_array ($newValue, $currentValue)) {
$itBeInThere = 1;
}
if ($itBeInThere != 1) {
array_unshift ($myArray, $newInsert);
}
--
http://www.php.net/manual/en/function.in-array.php
http://master.php.net/manage/user-notes.php?action=edit+24227
http://master.php.net/manage/user-notes.php?action=delete+24227
http://master.php.net/manage/user-notes.php?action=reject+24227