83266/how-to-store-values-from-foreach-loop-into-an-array
The code below does not work, only stores the last value, tried $items .= ..., but that is not doing the trick either, any help will be appreciated.
foreach($group_membership as $i => $username) { $items = array($username); } print_r($items);
Hello @kartik,
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);
Hope it helps!! Thank you!!
Hello, Php has a function for this, just ...READ MORE
Hello @kartik, Use JSON to transfer data types (arrays and ...READ MORE
Hello, Submitting multi-value form fields, i.e. submitting arrays ...READ MORE
Hello @kartik, Use COALESCE: DECLARE @Names VARCHAR(8000) SELECT @Names = ...READ MORE
Hey @kartik, First you have to go to ...READ MORE
Named route is used to give specific ...READ MORE
Hello, This is simple you just need to ...READ MORE
Hey @kartik, Named routing is another amazing feature of ...READ MORE
Hello @kartik, Use array_unique(): Example: $array = array(1, 2, 2, 3); $array ...READ MORE
Hello @kartik, Use this: foreach($array as $elementKey => $element) ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.