警告:substr_count():C:\ xampp \ htdocs \ tugasakhirhotel \ coba \ pesan \ index.php在第33行上的空子字符串

时间:2019-04-08 19:35:22

标签: php

如果有房间预订“回声已满”,我会进行酒店预订,

$stra = "1 2 4";          **/*rooms booked*/**
$strb = $ressi;           **/* all room from hotel (1,2,3,4,5,6,7,8,9,10)*/**
$arrayb = explode(",", $strb);

foreach($arrayb as $z){
    $countz = substr_count($stra,$z);
    if($countz==0){
        echo "empty".$z;
    }else if($countz==1){
        echo "full";
    }
}

如果$ stra处没有房间号,则回声为空;否则回声已满;

1 个答案:

答案 0 :(得分:0)

如果变量是我认为的变量,那么我认为更好的选择是将已预订的房间也爆炸到数组中,并使用array_diff查找可用的变量。

$stra = "1 2 4";          **/*rooms booked*/**
$strb = $ressi;           **/* all room from hotel*/**
$arrayb = explode(",", $strb);
$arraya = explode(" ", $stra);

var_dump(array_diff($arrayb, $arraya));
// Output is available rooms

在此处查看代码输出:https://3v4l.org/Q3kkn