For example, I have a function like this:
function loopValues()
{
$a = array('a','b','c');
foreach($a as $b)
{
$c = $b.'e';
echo $c;
}
}
How could I return its value aebece
in an array like ('ae','be','ce')
?
$a = array('a','b','c');
$b = array_map(function($ele) {
return $ele .= 'e';
}, $a);
Simple, try this:
function loopValues()
{
$a = array('a','b','c');
$r = array();
foreach($a as $b)
{
$c = $b.'e';
$r[] = $c;
}
return $r;
}
Try
function loopValues()
{
$a = array('a','b','c');
$result = array();
foreach($a as $b){
$result[] = $b.'e';
}
return $result;
}
$r = loopValues();
print_r($r);
See demo here
function loopValues(){
$a = array('a','b','c');
for($i=0;$i<count($a);$i++){
$a[$i] .= 'e';
}
return $a;
}