Forum Moderators: coopster

Message Too Old, No Replies

check values in array

         

omoutop

3:06 pm on Dec 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi to all!

I have constructed an aray with x values, how can I check if all values are the same? I want to check if or if not values are same and get the appropriate message...

Thx in advance

vincevincevince

3:09 pm on Dec 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Assuming $array[0] is the first element of the array:

foreach ($array as $a) if ($a!=$array[0]) {print "Not all the same"; exit();}

omoutop

3:26 pm on Dec 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



thx vincevincevince I 'll try it and report back

whoisgregg

3:43 pm on Dec 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



May want to use
break;
instead of
exit;
:)

vincevincevince

4:27 pm on Dec 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Good point, you should do that.

omoutop

12:31 pm on Dec 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thx both of you guys, works great!