PHP:检查并从阵列
阅读我有这样一个数组: -PHP:检查并从阵列
$arr = array(
"Sci-Fi",
"Action"
);
如何检查是否存在这个数组中Action
,以及它如何转换为(Sci-Fi,Action)
Thankx
在你的问题$ arr是数组。首先我们将检查'Action'是否在数组中。
if(in_array('Action',$arr)){
//in_array checks if 'Action' is in the array
echo "Action is in the array!";
}
现在我们需要“implode”数组将它变成一个字符串。
echo "(" . implode(',', $arr) . ")";
//implode glues the parts of your array together into a string using the supplied "glue", in this case a comma.
php.net拥有这一切的记载,但我知道这很难,只是知道什么是函数名称,尤其是神秘的东西一样破灭。当你学习时,很高兴得到一个友好的答案。
请解释你的解决方案。 –
我通常会发布答案,然后编辑它以添加更好的解释。如果我先把它写完,有人会用简单的答案来打败我。如此快速回答OP,然后解释组织的优点。这是众多可怕的行为之一,鼓励可怕的堆栈溢出策略。不要讨厌玩家,讨厌游戏。 – RightClick
我什么都不讨厌。我不知道每一个SO用户的习惯,我对社区的善意表现。这只是一个礼貌的提醒,不是个人的咆哮。 –
使用php在线文档。你可以使用[in-array](http://php.net/manual/ro/function.in-array.php)和[implode](http://php.net/manual/ro/function.implode。 php) – Filip