How to store values from foreach loop into an array?

前端 未结 8 752
我在风中等你
我在风中等你 2020-11-29 16:16

Need to store values from foreach loop into an array, need help doing that.

The code below does not work, only stores the last value, tried $items .= ...,

相关标签:
8条回答
  • 2020-11-29 16:40
    $items=array(); 
    $j=0; 
    
    foreach($group_membership as $i => $username){ 
        $items[$j++]=$username; 
    }
    

    Just try the above in your code .

    0 讨论(0)
  • 2020-11-29 16:45
    <?php 
    $items = array();
    $count = 0;
    foreach($group_membership as $i => $username) { 
     $items[$count++] = $username; 
    } 
    print_r($items); 
    ?>
    
    0 讨论(0)
提交回复
热议问题