How can I efficiently generate and assign second names to characters in a character creation menu using PHP?

When generating and assigning second names to characters in a character creation menu using PHP, one efficient way is to create an array of possible second names and randomly select one for each character. This can be achieved by using the `array_rand()` function to randomly pick an index from the array of second names.

// Array of possible second names
$secondNames = array("Smith", "Johnson", "Williams", "Jones", "Brown");

// Function to generate and assign second names to characters
function generateSecondName() {
    global $secondNames;
    return $secondNames[array_rand($secondNames)];
}

// Example of assigning a second name to a character
$characterSecondName = generateSecondName();
echo "Character's second name: " . $characterSecondName;