【问题标题】:how to check the value of an array in codeigniter如何在codeigniter中检查数组的值
【发布时间】:2013-04-26 12:49:21
【问题描述】:
$result=array();
$count = count($days);
for($i=0;$i<$count-1; $i++)
    {   
    $bookDate = $days[$i];
    $fromDate = $this->booking_model->Get_BookedDate($bookDate,$roomname);                                      
    if ($fromDate != 0)
    {
        $result[] = $bookDate;  
    }                   
}
return $result; 

这是我的 codeigniter 控制器功能,我想检查 $fromDate 的值是否为零。我得到这样的数组

 Array ( [0] => Array ( ["2013-04-27" between fromDate and toDate] => 1 ) )   

我对 codeigniter 很陌生。感谢您的帮助。

【问题讨论】:

  • 为什么你在foreach循环中比较只在外面比较,你确定只有一个匹配的日期输出会出现.............

标签: arrays codeigniter


【解决方案1】:
         $result=array();
         $count = count($days);
         for($i=0;$i<$count-1; $i++)
            {   
$bookDate = $days[$i];
$fromDate = $this->booking_model->Get_BookedDate($bookDate,$roomname);                                                      
if (!empty($fromDate[0]['"'.$bookDate.'" between fromDate and toDate']))
        {
        $result[] =$bookDate;   
        }                                                                   
              }
     return $result;

试试这个。它可以帮助你

【讨论】:

  • 我修好了。谢谢你的帮助
【解决方案2】:

利用empty()函数。

if(!empty($fromdate)) { //if $formdate is empty or 0 or false the loop won't be executed
  //Your code.
}

【讨论】:

    【解决方案3】:
    if (!empty($fromDate))
                   {
                $result[] = $bookDate;  
            }
    

    试试这个。

    【讨论】:

    • 感谢您的回复 循环正在执行 if Array ( [0] => Array ( ["2013-04-27" between fromDate and toDate] => 0 ) ) 和 Array ( [0 ] => Array (["2013-04-27" between fromDate and toDate] => 1 ) )
    • 如果数组值为1我想执行语句,如果数组值为0不执行语句
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-19
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    相关资源
    最近更新 更多