Waring:implode()[function.implode]:传递的参数无效

时间:2016-08-26 04:58:35

标签: php

  

Waring:implode()[function.implode]:传递的参数无效

if($_REQUEST['noofRooms']>0){
    for($i=0;$i<$_REQUEST['noofRooms'];$i++){
        $r_PackDetails =$_SESSION['PackDetails'][$i];
        $adults =$r_PackDetails['adults'];
        $childs =$r_PackDetails['childs'];
        $childAge_arr =$r_PackDetails['childAge'];
        $xmldata.='<Room><numberOfAdults>'.$adults.'</numberOfAdults>';
        if($childs>0){
            $childAge =implode(",",$childAge_arr);//ERROR occurs in this LINE
            $xmldata.='<numberOfChildren>'.$childs.'</numberOfChildren>';
            $xmldata.='<childAges>'.$childAge.'</childAges>';
        }

1 个答案:

答案 0 :(得分:0)

首先检查变量是否为数组。然后你将它传递给implode函数。如果该变量不是数组,那么它将抛出传递的无效参数。所以检查,

if(!empty($childAge_arr)) {
    $childAge =implode(",",$childAge_arr);
}