我很幸运能够从之前的帖子中收到此代码(翻转姓氏,名字)。
$name = "Lastname, Firstname";
$names = explode(", ", $name);
$name = $names[1] . " " . $names[0];
如何将函数应用于格式为$ginfo ->$(LastName, FirstName)
的数组中的每个值。
我尝试了下面的代码,但它不起作用。
$name1 =($ginfo->White);
$name1 = explode(", ", $name1); $FLw = $name1[1] . " " . $name1[0];
foreach ($name1 as ($ginfo->White)) {return($FLw);}
答案 0 :(得分:4)
使用array_map
功能:
function transpose($name)
{
$names = explode(", ", $name);
return $names[1] . " " . $names[0];
}
$transposed_array = array_map("transpose", $your_array);