Home >Backend Development >PHP Tutorial >新手求字符串转换成数组代码,该如何解决

新手求字符串转换成数组代码,该如何解决

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 10:08:43951browse

新手求字符串转换成数组代码
把字符串*id=3,express_no=25,ename=quanri,*id=4,express_no=17,ename=kuaidi,
转变成数组array(array(id=3,express_no=25,ename=quanri),array(id=4,express_no=17,ename=kuaidi))

------解决方案--------------------

PHP code
$s = "*id=3,express_no=25,ename=quanri,*id=4,express_no=17,ename=kuaidi,";$t = array();foreach(explode('*', $s) as $v) {  if(empty($v)) continue;  parse_str(str_replace(',', '&', $v), $t);  $r[] = $t;}print_r($r);<div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn