小编She*_*Pro的帖子

字符串和数组不像我想的那样工作

我正在尝试更多地了解字符串和数组.我有这段代码:

<?php
$states = "OH, VA, GA";
$arrayStates = explode(",", $states);
$exists = "GA";
print_r($arrayStates);

if (in_array($exists, $arrayStates)){
    echo "<br/>" . $exists . " " . "exists.";
} else {
    echo "<br/>" . $exists . " " . "doesn't exist.";
}
?>
Run Code Online (Sandbox Code Playgroud)

根据我的软弱思想,GA应该存在于数组中.如果我把$ exists ="OH",那就行了.但屏幕显示:

Array ( [0] => OH [1] => VA [2] => GA ) 
Run Code Online (Sandbox Code Playgroud)

GA不存在.

我在这里不理解什么?

php arrays string

0
推荐指数
1
解决办法
63
查看次数

标签 统计

arrays ×1

php ×1

string ×1