check all values in table or object
i would like make somethings:
<?php 
$a = array();
for ($i =0; $i<15; $i++){
 $a[$i] = '111';
}
foreach ($a as $ok){
 //if all values in $a == 开发者_运维问答111 : {
echo "all is 111"
} else {
echo "no";
}
}
?>
LIVE: http://codepad.org/RdvhK0VD
is function in PHP for this? i must each values check separately?
You can use array_count_values which will return an associative array of values and their frequencies.
If array_count_values($a) returns an array of length 1 and its key is '111', then $a contains only '111'.
$arr2 = array_count_values($a);
$key = '111';
if( count($arr2) == 1 && array_key_exists($key, $a) )
{
  // $a contains only $key
}
<?php 
    $a = array();
    for ($i =0; $i<15; $i++)
    {
        $a[$i] = '111';
    }
    $flag=true;
    foreach ($a as $ok)
    {
        if ( $a != 111 )
        {
            $flat=true;
        }
    }
    if(flag===true)
    {
        echo "all is 111"
    } else {
        echo "no";
    }
?>
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论