note 90405 added to function.array-unique
| From: | Ultimater at gmail dot com | Date: | Tue, 21 Apr 2009 01:26:03 +0000 |
| Subject: | note 90405 added to function.array-unique | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153527@lists.php.net to get a copy of this message | ||
Let's say you have
<?
$v=array("blue","blue","blue","blue");
if($v[0]==$v[1] && $v[1]==$v[2] && $v[2]==$v[3])
echo "Y"; else echo "N";//Y
?>
It works but the if-statement gets a bit messy if the number of array elements gets massive.
I find it is easier to use array_unique like so:
<?
$v=array("blue","blue","blue","blue");
echo sizeof(array_unique($v))==1?"Y":"N";//Y
?>
----
Server IP: 64.71.164.2
Probable Submitter: 76.94.233.193
----
Manual Page -- http://www.php.net/manual/en/function.array-unique.php
Edit -- https://master.php.net/note/edit/90405
Del: integrated -- https://master.php.net/note/delete/90405/integrated
Del: useless -- https://master.php.net/note/delete/90405/useless
Del: bad code -- https://master.php.net/note/delete/90405/bad+code
Del: spam -- https://master.php.net/note/delete/90405/spam
Del: non-english -- https://master.php.net/note/delete/90405/non-english
Del: in docs -- https://master.php.net/note/delete/90405/in+docs
Del: other reasons-- https://master.php.net/note/delete/90405
Reject -- https://master.php.net/note/reject/90405
Search -- https://master.php.net/manage/user-notes.php