我有这种情况
$array2 = array();
for($i=1;$i<=3;$i++){
$key_page_number = $key."?page=".$i;
$key_page_number = $this->get_page_with_check_error($key_page_number);
preg_match_all("~<div class=\"desc-zone\">\s*<a\sitemprop=\"url\"\shref=\"(.*?)\"~", $key_page_number, $product_urls);
$array2[] = $product_urls[1];
}
我的array2看起来像这样
[1] => Array(
[0] => something
[1] => something
)
[2] => Array(
[0] => something
[1] => something
)
[3] => Array(
[0] => something
[1] => something
)
我想让我的array2看起来像这样
[1] => Array(
[0] => something
[1] => something
[2] => something
[3] => something
[4] => something
[5] => something
)
我如何合并数组的这个元素?
答案 0 :(得分:0)
<?php
$data =
[
[
'foo',
],
[
'bar'
]
];
$first_key = array_keys($data)[0];
$out[$first_key] = array_merge(...$data);
var_export($out);
输出:
array (
0 =>
array (
0 => 'foo',
1 => 'bar',
),
)