关于数组重组。该怎么处理
程序员文章站
2022-06-16 15:00:39
...
关于数组重组。
------解决方案--------------------
------解决方案--------------------
另类的写法
(
[0] => Array
(
[url] => 123
)
[1] => Array
(
[url] => 456
)
[2] => Array
(
[url] => 789
)
)
Array
(
[0] => 123
[1] => 456
[2] => 789
)
$url = array('123','456','789');
能将上面这个数组,组装成下面的这个吗?
$urls = array(array('url'=>'123'),array('url'=>'456'),array('url'=>'789'));
Array
(
[0] => Array
(
[url] => 123
)
[1] => Array
(
[url] => 456
)
[2] => Array
(
[url] => 789
)
)
------解决方案--------------------
foreach ($url as $url_value) {
$urls[] = array('url'=>$url_value);
}
------解决方案--------------------
另类的写法
$ar = array(123, 456, 789);Array
$t = array_map('array_combine',array_chunk(array_fill(0,count($ar), 'url'), 1), array_chunk($ar, 1));
print_r($t);
(
[0] => Array
(
[url] => 123
)
[1] => Array
(
[url] => 456
)
[2] => Array
(
[url] => 789
)
)
相关文章
相关视频