开发者

How do I apply a string function to an array?

开发者 https://www.devze.com 2022-12-26 19:18 出处:网络
I was fortunate enough to receive this code (flips Lastname, Firstname) from an earlier post. 开发者_高级运维

I was fortunate enough to receive this code (flips Lastname, Firstname) from an earlier post.

开发者_高级运维
$name = "Lastname, Firstname";
$names = explode(", ", $name);
$name = $names[1] . " " . $names[0];

How do I apply the function to each value in an array that is in the form: $ginfo ->$(LastName, FirstName).

I tried the code below, but it doesn't work.

$name1 =($ginfo->White); 
$name1 = explode(", ", $name1);  $FLw = $name1[1] . " " . $name1[0]; 
foreach ($name1 as ($ginfo->White)) {return($FLw);}


Use the array_map function:

function transpose($name)
{
    $names = explode(", ", $name);
    return $names[1] . " " . $names[0];
}

$transposed_array = array_map("transpose", $your_array);
0

精彩评论

暂无评论...
验证码 换一张
取 消