How to store values from foreach loop into an array?

前端 未结 8 862
我在风中等你
我在风中等你 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:21

    Declare the $items array outside the loop and use $items[] to add items to the array:

    $items = array();
    foreach($group_membership as $username) {
     $items[] = $username;
    }
    
    print_r($items);
    

提交回复
热议问题