PGo*_*How 0 php arrays comparison string-comparison comparison-operators
如何将一个值与特定数组中的每个值进行比较?
例如:
$list = ("blue", "red", "green", "yellow", "orange", "white");
$value = "blue";
if ($value == $list)
{
// then print "This is BLUE";
}
Run Code Online (Sandbox Code Playgroud)
我只需要一次确定颜色,不需要重复打印其他颜色.
这可能会让我实现从数据库中检索的动态值,然后比较PHP脚本中的[hardcode]数组.然后,将精确值匹配返回到屏幕上,例如上面的场景.
你能找到in_array()吗?
if (in_array('blue', $colors)) {
// the color blue is there
}
Run Code Online (Sandbox Code Playgroud)