在PHP中将字符串如id = 1&type = 2转换为数组的最快方法?
发布时间:2020-12-13 22:07:00 所属栏目:PHP教程 来源:网络整理
导读:我需要将其更改为: $arr['id']=1;$arr['type']=2; 解决方法 使用: parse_str(). void parse_str(string $str [,array $arr]) Parses str as if it were the query string passed via a URL and sets variables in the current scope. 例: ?php $str = "fi
我需要将其更改为:
$arr['id']=1; $arr['type']=2; 解决方法
使用:
parse_str().
void parse_str(string $str [,array &$arr])
例: <?php $str = "first=value&arr[]=foo+bar&arr[]=baz"; parse_str($str); echo $first; // value echo $arr[0]; // foo bar echo $arr[1]; // baz parse_str($str,$output); echo $output['first']; // value echo $output['arr'][0]; // foo bar echo $output['arr'][1]; // baz ?> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |