这个有点难以解释,但我会尽力说清楚。
我怎样才能做到这一点,以便在函数多次调用完成后,我可以将循环内的数组的所有元素插入到新数组中?
例如,如果这个函数在循环中被多次调用。函数调用完成后,var_dump显示的array1、array 2、array3合并到一个数组中,使用array_merge后新数组$array_total具有array1、array2和array3的元素,我该怎么办?一个例子将不胜感激!
<?php
function data($param1, $param2) {
$new_array = array();
echo $param1."-".$param2;
foreach($products as $key => $value) {
array_push($new_array,$value); // inserts all the values of array $products into new array $new_array everytime the function is called.
}
var_dump($new_array); // this will generate will display array(1), array(2) and array(3) if the function below has been called 3 times for example .
}
foreach($form as $form_id => $form_title) {
data($form_id,$form_title);
}
?>