Home  >  Article  >  Backend Development  >  php Array数组转换有关问题

php Array数组转换有关问题

WBOY
WBOYOriginal
2016-06-13 11:20:59858browse

php Array数组转换问题
如何把

<br />Array<br />(<br />    [strwarenum] => Array<br />        (<br />            [0] => 1<br />            [1] => 1<br />        )<br /><br />    [strwareid] => Array<br />        (<br />            [0] => 80<br />            [1] => 79<br />        )<br /><br />)


转换为

<br />Array<br />(<br />    [config_id] => <br />    [strwareid] => ,78,80<br />    [strwarenum] => ,1,1<br />    [config_name] => <br />    [config_desc] => <br />    [diycat_id] => <br />)

并可以单独调用呢

PHP
------解决方案--------------------
设你原来的数组为$a,建一个你需要包含所有key的空数组$b(你的例子有些key在$a中没有,所以要另建)
不知道你的78这个值从何而来,暂时当你是把79打错了
我懒得写赋值部分了,还要改你的代码,麻烦,自己写吧
foreach($b as $k => $v){<br />    $a[$k][]='';<br />    $v=array_reverse($a[$k]);<br />}<br />var_export($b);<br />

自己测试
------解决方案--------------------
$arr=你的数组;<br />foreach($arr as &$v){<br />     if(is_array($v)) $v=','.join(',',$v);<br />}<br />print_r($arr);
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