2014-01-06 17:09
浏览 569


I am wondering how can I store all values from a foreach loop, I know that I am re-initialising in the loop but I'm not sure how to store the data. Heres my basic loop:

$array = array("v1", "v2", "v3", "v4");
foreach($array as $row){
    $arr = array('val' => $row);
    echo $row;

So when I use the print_r($arr) the only thing outputted would be v4 and I know that the values are there because the echo $row; does return each output individually.

My question would be how can I store each instance of row in my array?

图片转代码服务由CSDN问答提供 功能建议

我想知道如何存储来自foreach循环的所有值,我知道我正在重新初始化 循环,但我不知道如何存储数据。 继承我的基本循环:

  $ array = array(“v1”,“v2”,“v3”,“v4”); 
foreach($ array as $ row)  {
 $ arr = array('val'=> $ row); 
 echo $ row; 
nprint_r($ arr); 

所以当我使用 print_r($ arr)时,输出的唯一内容就是 v4 ,我知道值是因为 echo $ row; < / code>确实单独返回每个输出。


  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题