我创建城市如果阵列包括PHP
$cities = explode("|", $city);
现在我想搜索该阵列,看它是否包含特定城市的if语句的数组。像这样...
If($cities includes(London)){
Do code;
}
我该怎么做?
我创建城市如果阵列包括PHP
$cities = explode("|", $city);
现在我想搜索该阵列,看它是否包含特定城市的if语句的数组。像这样...
If($cities includes(London)){
Do code;
}
我该怎么做?
if (in_array('London', $cities)) {
[...]
}
只需使用in_array
http://php.net/manual/en/function.in-array.php
例子:
<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
echo "Got Irix";
}
if (in_array("mac", $os)) {
echo "Got mac";
}
?>
可以使用功能in_array():
if (in_array("London", $cities)) {
Do code;
}