How to store values from foreach loop into an array? How to store values from foreach loop into an array? php php

How to store values from foreach loop into an array?


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);


Use

$items[] = $username;


Try

$items = array_values ( $group_membership );