I need to reverse the orientation of the first name and last name in an array of name strings.
$names = [
"barira, stefan",
"cikka, maria",
"luppo, martin ",
"bill, sebastian"
];
the output must be like this:
Array ( [0] => stefan, barira
[1] => maria, cikka
[2] => martin, luppo
[3] => sebastian, bill )
I got close with this code, but I want it to be like the output above:
$names = [
"barira, stefan",
"cikka, maria",
"luppo, martin ",
"bill, sebastian"
];
for ($i = 0; $i < count($names); $i++) {
$words = $names[$i];
$string = explode(' ', $words);
$string = array_reverse($string);
$reverse = implode(' ', $string);
print_r($reverse);
}