Codeigniter结合信息

时间:2014-02-13 20:49:30

标签: php codeigniter if-statement model

首先,只是想让你知道我是CI的新手。但是我遇到了这段代码的问题,而且我似乎无法在任何地方找到答案。

由于某种原因,代码在第一个if语句中断了...如果可能的话,你可以帮我理解那里真正发生了什么吗?

谢谢大家的帮助!

function main
{
$this->load->model(getData) psudo code for this area...
}

--- ---模型     函数getData ....     {     Sql = this-> db-> query(返回所有必需信息的sql代码。)     $ result = $ sql-> result_array();

$types = array ( 'EVENT|TIME' => array( 'id' => 1, 'name' => 'Regular' ),
        'PROPOSITION|REGULAR' => array( 'id' => 2, 'name' =>'Propositions'),
        'EVENT|TIME' => array( 'id' => 3, 'name' => 'Now' ),
        'PROPOSITION|FUTURES' => array( 'id' => 4, 'name' => 'Future' ));
$var = array();
foreach ($result as $event) {
    $cat = $event['type'] . '|' . $event['sub_type'];
        $typeId = $types[$cat]['id'];

    if(!is_array($var[$event['event_id']]['var'][$event['type_id']]))                               
               { 
       if(!is_array($var[$event['event_id']]))
                 {
        $var[$event['event_id']] = array( 'event_name' =>            
                    $event['event_name'],'event_abbreviation' => 
                    $event['event_abbreviation']);                                      
                 }

        $var[$event['event_id']]['var'][$event['type_id']] =  array(  
          'type_name' => $event['abbreviation'],'type_abbreviation' => $event['name']                                                                                                                                               
        );
    }

    $event[$event['event_id']]['var'][$event['type_id']]['types'][$typeId] = 
      $types[$cat]['name'];

}

return $myResults;
 }

1 个答案:

答案 0 :(得分:0)

在这一行

if(!is_array($var[$event['event_id']]['var']$event['type_id']])) 

你错过了[。我在$event['type_id']之前猜测 所以替换为:

if(!is_array($var[$event['event_id']]['var'][$event['type_id']]))