使用in_array和multidimensional-array时收到警告

时间:2015-09-22 06:30:52

标签: php arrays multidimensional-array yii

我创建一个数组并通过php(yii框架)中的代码用变量(索引和值)填充它。但我的程序不能正常工作。填写后我无法使用我的阵列。

模型Lookup.php中的

private static $row_flags= array();
private static $table_flags= array();


public static function checkStatus($value,$row,$column) {

    $thresholds= hreshold::model()->findAll(array('select'=>$row.','.$column));
    self::$row_flags['browsing'][$row][$column]=($value < $thresholds[0]->$row) ?"green":(($value > $thresholds[0]->$column)?"red":"yellow");
    return self::$row_flags['browsing'][$row][$column];

}

public static function getRowFlag() {

        return self::$row_flags;

    }

public static function row_color($table,$row){

   return in_array("yellow",self::$row_flags['browsing'][$row]);
  }  

view.php

<?php 
    lookup::checkStatus(3001,'http','access');
    lookup::checkStatus(3001,'http','access');
    lookup::checkStatus(3001,'http','core');
    lookup::checkStatus(3001,'http','blackbox');
    lookup::checkStatus(3001,'http','gateway');
    lookup::checkStatus(3001,'http','internet');

    print_r(lookup::getRowFlag());
?>
     Array
      (
           [browsing] => Array
                           (
                              [http] => Array
                                          (
                                              [access] => yellow
                                              [core] => yellow
                                              [blackbox] => yellow
                                              [gateway] => yellow
                                              [internet] => yellow
                                           )
                            )
      ) 

如果我在视图中调用Lookup::row_color('browsing','http')

  

警告:in_array()期望参数2为数组,给定

为null

2 个答案:

答案 0 :(得分:0)

也许专栏是麻烦制造者: 而不是l(array('select'=>$row.','.$column));

使用l(array('select'=>$row.','.'select'=>$column));

答案 1 :(得分:-2)

使用此:

public static function row_color($table,$row){
  if (is_array(self::$row_flags['browsing'][$row])) {
    return in_array("yellow",self::$row_flags['browsing'][$row]);
  }
  return FALSE;
}