note 21666 modified in function.array-search by vrana

From: Date: Tue, 17 Aug 2004 14:49:21 +0000
Subject: note 21666 modified in function.array-search by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79782@lists.php.net to get a copy of this message
The function posted by 'chen.avinadav@vbulletin.com' on '13-Apr-2002 04:15' is wrong! You are matching the value not the key. It should read: <?php function array_search($needle, $haystack) { $match = false; foreach ($haystack as $key => $value) { if ($value == $needle) { $match = $key; } } return $match; } ?> --was-- The function posted by 'chen.avinadav@vbulletin.com' on '13-Apr-2002 04:15' is wrong! You are matching the value not the key. It should read: function array_search($needle, $haystack) { $match = false; foreach ($haystack as $key => $value) { if ($value == $needle) { $match = $key; } } return $match; } http://php.net/manual/en/function.array-search.php

« previous php.notes (#79782) next »