Tags
PHP , String
Asked 2 years ago
14 Jul 2021
Views 498
Maiya

Maiya posted

Best way to split a first and last name in PHP


$name="maiiya chandra";
echo $firstname;
echo $lastname;


how to divide the string some how i get the first and last name in php
jessica

jessica
answered Jul 17 '21 00:00

explode string with space and you will get array with two value one is the firstname and lastname


$name="maiiya chandra";
$name_array=explode(" ",$name);
$firstname=$name_array[0];
$lastname=$name_array[1];
echo "firstname is ".$firstname;
echo "lastname is ".$lastname;
Post Answer