1

在下面的代码中,如何检查是否$variable等于“$one”。

<?php  
    $one = array (1,2,3);
    $two = array (4,5,6);

    $variables = array ($one, $two);

    foreach ($variables as $variable){
        //check if the $variable is equal to "$one"
            //do stuff that is specific for array $one
    }   
?>
4

4 回答 4

4

欲了解更多信息,请访问

<?php  
    $one = array (1,2,3);
    $two = array (4,5,6);

    $variables = array ($one, $two);

    foreach ($variables as $variable){
        //check if the $variable is equal to "$one"
           if($variable === $one)
            //do stuff
    }   
?>
于 2012-09-03T10:42:30.690 回答
1

简单地说,你不能。不过,您可以为这些值添加一个键:

<?php  
$one = array (1,2,3);
$two = array (4,5,6);

$variables = array ( 'one' => $one, 'two' => $two);

foreach ($variables as $key => $variable){
    //check if the $variable is equal to "$one"
    if( $key === 'one' ) {
        //do stuff that is specific for array $one
    }
}   
于 2012-09-03T10:41:51.997 回答
1
  foreach ($variables as $variable){
        if($variable == $one)//TRUE if $a and $b have the same key/value pairs.
        {

        }
    } 

如果您还想检查订单和类型,您可以执行以下操作:

  foreach ($variables as $variable){
        if($variable === $one)
        {

        }
    } 
于 2012-09-03T10:43:14.243 回答
1

你可以检查

if($variable===$one)

您正在使用多维数组。请记住,您需要检查“===”,而不是“==”,因为它不是变量,甚至不是字符串。

于 2012-09-03T10:57:24.733 回答