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);
More Related Contents:
- How to make array inside in foreach loop – php? [closed]
- Can't echo items from array
- CodeIgniter – foreach loop
- How does PHP ‘foreach’ actually work?
- Two arrays in foreach loop
- Performance of foreach, array_map with lambda and array_map with static function
- How can I loop through two arrays at once? [duplicate]
- How to find the foreach index?
- Find the last element of an array while using a foreach loop in PHP
- Trying to get property of non-object in [duplicate]
- How to access mysql result set data with a foreach loop
- How do you remove an array element in a foreach loop?
- PHP foreach with Nested Array?
- PHP Error : Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` [duplicate]
- How to delete object from array inside foreach loop?
- Binding params for PDO statement inside a loop
- What is better in a foreach loop… using the & symbol or reassigning based on key?
- PHP foreach by reference causes weird glitch when going through array of objects
- PHP: Get the key from an array in a foreach loop [duplicate]
- Removing last comma from a foreach loop
- Timeout a function in PHP
- Get next element in foreach loop
- break out of if and foreach
- Multiple index variables in PHP foreach loop
- PHP: Limit foreach() statement? [closed]
- php multidimensional array get values
- How to check if variable is array?… or something array-like
- What does $k => $v in foreach($ex as $k=>$v) mean? [duplicate]
- foreach with three variables add
- limiting number of times a loop runs in php