Home >Backend Development >PHP Tutorial > 关于数组重组。该怎么处理
关于数组重组。
Array<br /> (<br /> [0] => 123<br /> [1] => 456<br /> [2] => 789<br /> )<br /> $url = array('123','456','789');<br /> 能将上面这个数组,组装成下面的这个吗?<br /> <br /> $urls = array(array('url'=>'123'),array('url'=>'456'),array('url'=>'789'));<br /> <br /> <br /> <br /> <br /> <br /> <br /> Array<br /> (<br /> [0] => Array<br /> (<br /> [url] => 123<br /> )<br /> <br /> [1] => Array<br /> (<br /> [url] => 456<br /> )<br /> <br /> [2] => Array<br /> (<br /> [url] => 789<br /> )<br /> <br /> )
<br /> foreach ($url as $url_value) {<br /> $urls[] = array('url'=>$url_value);<br /> }<br />
$ar = array(123, 456, 789);<br /> $t = array_map('array_combine',array_chunk(array_fill(0,count($ar), 'url'), 1), array_chunk($ar, 1));<br /> print_r($t);Array