Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php stop explode()要求参数2为字符串警告_Php_Get_Explode - Fatal编程技术网

Php stop explode()要求参数2为字符串警告

Php stop explode()要求参数2为字符串警告,php,get,explode,Php,Get,Explode,我有一个表单,允许用户选择2个或更多类别 php检查url,如: $categories= (!isset($_GET["categories"])?0:explode(";",$_GET["categories"])); 正常的URL是这样的 site.com/cat.php?page=&categories=1;2 is_string($_GET["category"]) 如果用户将URL更改为 site.com/cat.php?page=&

我有一个表单,允许用户选择2个或更多类别

php检查url,如:

 $categories= (!isset($_GET["categories"])?0:explode(";",$_GET["categories"]));
正常的URL是这样的

    site.com/cat.php?page=&categories=1;2
     is_string($_GET["category"])
如果用户将URL更改为

    site.com/cat.php?page=&categories[1]
网站将显示

      Warning: explode() expects parameter 2 to be string, array given in...
所以我试着检查$你得到这样的结果

    site.com/cat.php?page=&categories=1;2
     is_string($_GET["category"])
但如果运气不好,试试这个

$catString=is_string($_GET["categories"]) ? $_GET["categories"] : implode(';',$_GET["categories"]);

$categories = (!isset($_GET["categories"])?0:explode(";",$catString));
或者我想更好的解决方案是(而不是从数组转换为字符串,再转换回数组,这有点愚蠢):

如果是数组,则使用内爆爆炸功能