I have this code,
$salt = str_pad(rand(1, 9999999), 7, '0', STR_PAD_LEFT);
Does it mean, the number will be random between 1, 9999999.
It will be at least 7 characters long.
If the rand isn't 7 numbers long zeros will be added to the right until it makes up seven number in total?
If that is correct, as I am unsure how can I change this so instead of inserting just zeros to make a total of 7, but to generate a random number between 1 and 9, and add those to make it a total number of 7.
Yes, I believe your interpretation is accurate.
I wouldn't bother changing it; making the padding digits random won't make your number any more random. In fact, if anything, you'd be skewing the distribution, making lower numbers quite a lot less likely.
$salt = str_pad(rand(1, 9999999), 7, rand(1, 9), STR_PAD_LEFT);
Rather than passing 0 to pad with, just pass a random number from 1 to 9.
Your understanding is basically correct. It will give you a random number from 1 to 9999999 and then give you a string representation with zero padding on the left.
If you just want a 7-digit random number, use:
rand(1000000,9999999)
If you want a specific non-zero digit to pad it with (all digits the same), generate one randomly with rand(1,9)
and use it, along the lines of:
$salt = str_pad(rand(1, 9999999), 7, <your random character here>, STR_PAD_LEFT);