I have an array that I loop through with for each loop it returns only the first iteration but if I change it to echo it prints all of them to the screen, new to PHP not sure wh
return always exits the function and returns its argument. From the docs:
If called from within a function, the return statement immediately ends execution of the current function, and returns its argument as the value of the function call.
If you don't want this to happen, try appending to a variable, and returning it when you've finished appending:
function getData ($values) {
$form = '';
foreach ($values as $key => $value) {
$form .= "". $key . " " . $value ."
";
}
return $form;
}