【问题标题】:how to run condition in php array如何在php数组中运行条件
【发布时间】:2015-10-26 12:54:48
【问题描述】:

嗨,我有如下给出的数组,我需要运行逻辑条件。 请建议我如何运行此代码,然后输出将匹配数组条件。

Array
(
    [0] => Array
    (
        [match] => FALSE
        [coundition] => 
    )

    [1] => Array
    (
        [coundition] => or            
        [match] => TRUE

    )

    [2] => Array
    (
    [coundition] => and            
    [match] => FALSE

    )

    [3] => Array
    (
        [coundition] => and            
        [match] => TURE
    )

)

想像

if($match[0]==TRUE || $match[1]==TRUE && $match[2]==TRUE && $match[3]==FALSE  )
{
    $output=1;
}else
{
    $output=0;
}

【问题讨论】:

  • 应该是$myArray[0]['match']而不是$match[0]来获取match键的值。

标签: php arrays codeigniter


【解决方案1】:

如果我正确理解了您的问题,那么这将对您有所帮助!

<?php

$arr = array(array("MATCH" => "FALSE", "CONDITION" => "OR"),
             array("MATCH" => "TRUE", "CONDITION" => "AND"),
             array("MATCH" => "TRUE", "CONDITION" => "AND"),
             array("MATCH" => "FALSE", "CONDITION" => "OR")

);

echo "<pre>";
print_r($arr);
echo "</pre>";


if($arr[0]["MATCH"]=="TRUE" || $arr[1]["MATCH"]=="TRUE" && $arr[2]["MATCH"]=="TRUE"
        && $arr[3]["MATCH"]=="FALSE" ) {
    echo "The output is 1";
}

else {
    echo "The output is 0";
}

?>

输出

Array
(
[0] => Array
    (
        [MATCH] => FALSE
        [CONDITION] => OR
    )

[1] => Array
    (
        [MATCH] => TRUE
        [CONDITION] => AND
    )

[2] => Array
    (
        [MATCH] => TRUE
        [CONDITION] => AND
    )

[3] => Array
    (
        [MATCH] => FALSE
        [CONDITION] => OR
    )

)

The output is 1

【讨论】:

  • 如何使用 match 运行边数组中的条件。
猜你喜欢
  • 1970-01-01
  • 2011-03-25
  • 2018-09-14
  • 2011-10-11
  • 2021-11-29
  • 1970-01-01
  • 1970-01-01
  • 2021-02-17
  • 1970-01-01
相关资源
最近更新 更多