Monday, 2 February 2015

Array Values Similar

Array Values Similar

This happy little function checks if all the values in an array are the same. As with most things involving PHP this can be done a number of ways, but this is the one for you...

<?php

error_reporting
(E_ALL);/*** specify and array of values ***/$array = array('valid''valid''valid''valid''valid''valid''valid');
/**
 *
 * @check if array values are the same
 *
 * @param array $array
 *
 * @return bool
 *
 */
function array_values_similar($array) {$values array_count_values($array);

if(
array_key_exists('valid'$values) && $values['valid'] == sizeof($array))
    {
    return 
true;
    }
else
    {
    return 
false;
    }
}
?>

0 comments:

Post a Comment