我有一个php mysql查询结果如下...
Array
(
[0] => stdClass Object
(
[id] => 52
[sku] =>
[name] => stone product 52
)
[1] => stdClass Object
(
[id] => 53
[sku] =>
[name] => stone product 53
)
.
.
.
)
Array
(
[0] => stdClass Object
(
[id] => 12
[sku] =>
[name] => stone product 12
)
[1] => stdClass Object
(
[id] => 13
[sku] =>
[name] => stone product 13
)
.
.
.
)我想要的结果如下
Array(
[0] => stdClass Object
(
[id] => 52
[sku] =>
[name] => stone product 52
)
[1] => stdClass Object
(
[id] => 53
[sku] =>
[name] => stone product 53
)
[2] => stdClass Object
(
[id] => 12
[sku] =>
[name] => stone product 12
)
[3] => stdClass Object
(
[id] => 13
[sku] =>
[name] => stone product 13
)在单个数组中
请给我推荐php代码
发布于 2013-07-11 05:13:37
你不应该在php中加入这些结果。使用one query获取这两组结果,这将减少您的数据库读取。
发布于 2013-07-11 05:14:29
您可以使用array_merge函数:http://php.net/manual/en/function.array-merge.php
如果您正在处理内部有数组的数组,则可以使用foreach调用合并它们
$my_array=get_the_result_from_mysql();//Here how do you get the result.
$new_array=array();
foreach ($my_array as $row) {
$new_array=array_merge($new_array,$row);
}
var_dump($new_array);我想这对你有帮助。
https://stackoverflow.com/questions/17580903
复制相似问题