[英]PHP how to merge array in foreach loop
How do i merge all $related_array
in the foreach loop into 1 array not multidimesional. 如何将foreach循环中的所有$related_array
合并为1个数组而不是多维数组。
$get_categories = $wpdb->get_results("SELECT related FROM wp_pato_category_related WHERE slug IN ('$categories')");
foreach($get_categories as $array) {
$related_array = unserialize($array->related);
}
You can flatten the array using Standard PHP Library (SPL) 您可以使用标准PHP库(SPL)展平数组
So in your code, flatten $related_array with RecursiveArrayIterator
因此,在您的代码中,使用RecursiveArrayIterator
$ related_array展平
$related_flat = new RecursiveIteratorIterator(new RecursiveArrayIterator($related_array));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.