note 24227 deleted from function.in-array by sobak

From: Date: Sat, 25 Feb 2017 06:05:33 +0000
Subject: note 24227 deleted from function.in-array by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208844@lists.php.net to get a copy of this message
Note Submitter: tom at orbittechservices dot com ---- 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); } ?>

« previous php.notes (#208844) next »