如何在完成php循环后将更多数据推入数组?

如何在完成php循环后将更多数据推入数组?

问题描述:

im trying to do something here with php, i want after the loop finishes looping with the data array to add more data into the array and again start looping.

i.e.

    foreach($arrayData->data as $item) {

         echo $item->id;


    }

   //add more data to $arrayData 
   //and do the foreach loop again

i dont now if this is impossible but i thought let me give it a try and ask, thank. ps. this is not the all the code on the page, but i tried to make it simple fro your eyes :))

我试图用php做一些事情,我希望在循环完成循环后使用数据数组添加更多数据 进入数组并再次开始循环。 p>

ie p>

  foreach($ arrayData-> data as $ item){
 \  n echo $ item-> id; 
 
 
} 
 
 //将更多数据添加到$ arrayData 
 //并再次执行foreach循环
  code>  pre> 
  
 

我现在不知道如果这是不可能的,但我想让我试一试,问问,谢谢。 ps。 这不是页面上的所有代码,但我试图让你的眼睛变得简单:)) p> div>

I guess you can do either of the following

use

array_push($arrayData->data, "val1", "val2");

or use simple array assignment like

$arrayData->data["another key"]  = "another value";

I am assuming that $arrayData->data is your array

By the look of thing your $item is an object too. So replace the string values with your objects