I want the foreach
to return arrays but it just returns a single array. But the array_map with
same code does.
- What is the correct way of getting the arrays out of the
foreach
. - Why does
foreach
behaves differently thanarray_map
.
Inside the file (userdata.php)
Reme:[email protected]
george bush:[email protected]
obama:[email protected]
Using array_map
function registered_users(){
$file_user = file('userdata.php');
return array_map(function($user){
return explode(':',$user);
},$file_user);
} //returns the exploded array correctly.
Using foreach
function registered_users(){
$file_user = file('userdata.php');
foreach ($file_user as $user) {
return explode(':',$user);
}
}// returns Array ( [0] => Reme [1] => [email protected] )
array_map
why is it not moving out ?