Generate Random Strings And Numbers in PHP

How to create a random string of PHP. The code below for creating a unique ID number function.

PHP Random String Function

This PHP random_strings() function creates a combination of uppercase and lowercase letters, including underscore.
JavaScript
<?php
function random_strings($length = 10) {
    $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_';
    $chars_length = strlen($chars);
    $string = '';
    for ($i = 0; $i < $length; $i++) {
        $string .= $chars[rand(0, $chars_length - 1)];
    }
    return $string;
}

//usage. set strings length 
echo random_strings(15); //output d8iSfUi8484_rij

?>

PHP Random Number Function

This PHP random_numbers() function generates mixed numbers.
JavaScript
<?php
function random_numbers($length = 10) {
    $numbers = '0123456789';
    $numbers_length = strlen($numbers);
    $number = '';
    for ($i = 0; $i < $length; $i++) {
        $number .= $numbers[rand(0, $numbers_length - 1)];
    }
    return $number;
}

//usage
echo random_numbers(15); //659854320686554
?>