Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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 将字符串放入具有键值对的数组中_Php_Arrays_String_Serialization - Fatal编程技术网

Php 将字符串放入具有键值对的数组中

Php 将字符串放入具有键值对的数组中,php,arrays,string,serialization,Php,Arrays,String,Serialization,我已将文件序列化 "date_from=&time_from=&date_to=&time_to=&email=&title=&text=&date_from_full=&date_to_full=&sortID=SortiddReverse&" 我需要转换成带有键值对的数组,我试过了。explode,但它没有按我需要的那样工作 0 => "date_from=" 1 => "time_from=

我已将文件序列化

"date_from=&time_from=&date_to=&time_to=&email=&title=&text=&date_from_full=&date_to_full=&sortID=SortiddReverse&"
我需要转换成带有键值对的数组,我试过了。explode,但它没有按我需要的那样工作

 0 => "date_from="
  1 => "time_from="
  2 => "date_to="
  3 => "time_to="
  4 => "email=1"
  5 => "title=1111"
  6 => "text=1111"
  7 => "date_from_full="
  8 => "date_to_full="
  9 => "sortID=SortiddReverse"
  10 => ""

如何解决这个问题?

PHP中已经有一个函数用于检索您请求的键/值对

$string = "date_from=&time_from=&date_to=&time_to=&email=&title=&text=&date_from_full=&date_to_full=&sortID=SortiddReverse&";

$array = [];
parse_str($string, $array):
并将输出

array(10) {
  'date_from' =>
  string(0) ""
  'time_from' =>
  string(0) ""
  'date_to' =>
  string(0) ""
  'time_to' =>
  string(0) ""
  'email' =>
  string(0) ""
  'title' =>
  string(0) ""
  'text' =>
  string(0) ""
  'date_from_full' =>
  string(0) ""
  'date_to_full' =>
  string(0) ""
  'sortID' =>
  string(14) "SortiddReverse"
}

你试过什么?您的源代码在哪里?您要求的是键/值对,但列出一个编号的数组作为预期结果?