note 24227 modified in function.in-array by danbrown
| From: | danbrown@php.net | Date: | Mon, 08 Jun 2009 21:47:33 +0000 |
| Subject: | note 24227 modified in function.in-array by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156531@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;
<?php
$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);
}
?>
--was--
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://php.net/manual/en/function.in-array.php