Source Code:
(back to article)
<?php // Define a string with the full name $name = "John Smith"; // Split the full name into parts $name_parts = explode(" ", $name); // Extract the last name $last_name = array_slice($name_parts, -1)[0]; // Output the last name echo "Last name: " . $last_name . "\n"; // Output: // Last name: Smith ?>
Result:
Report an issue