public static function allElementsEqual(array $haystack, $needle = null)
    {
        $return = true;
        // if both arguments have been passed, use value argument (regardless of whether it is null or not
        if (func_num_args() == 2) {
            $compareAgainst = $needle;
        } // only one argument has been passed, so compare elements only to each other
        else {
            $compareAgainst = reset($haystack);
        }
        foreach ($haystack as $element) {
            if ($compareAgainst != $element) {
                $return = false;
                break;
            }
        }

        return $return;
    }
public static function allElementsEqual(array $haystack, $needle = null)
    {
        $return = true;
        // if both arguments have been passed, use value argument (regardless of whether it is null or not
        if (func_num_args() == 2) {
            $compareAgainst = $needle;
        } // only one argument has been passed, so compare elements only to each other
        else {
            $compareAgainst = reset($haystack);
        }
        foreach ($haystack as $element) {
            if ($compareAgainst != $element) {
                $return = false;
                break;
            }
        }

        return $return;
    }
public static function allElementsEqual ( array $ haystack , $ needle = null ) { $ return = true ; // if both arguments have been passed, use value argument (regardless of whether it is null or not if ( func_num_args ( ) == 2 ) { $ compareAgainst = $ needle ; } // only one argument has been passed, so compare elements only to each other else { $ compareAgainst = reset ( $ haystack ) ; } foreach ( $ haystack as $ element ) { if ( $ compareAgainst != $ element ) { $ return = false ; break ; } } return $ return ; }
Checks if all elements of the array have same value

@param array $haystack
@param mixed $needle

@return boolean
Checks if all elements of the array have same value