note 90405 modified in function.array-unique by danbrown

From: Date: Tue, 21 Apr 2009 01:50:56 +0000
Subject: note 90405 modified in function.array-unique by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153529@lists.php.net to get a copy of this message
Let's say you have <?php $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: <?php $v=array("blue","blue","blue","blue"); echo sizeof(array_unique($v))==1?"Y":"N";//Y ?> --was-- 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 ?> http://php.net/manual/en/function.array-unique.php

« previous php.notes (#153529) next »