I am generating an integer from 5-10.
once I generate an integer ranging from 5-10, the loop should choose a string on my array that has a character length based on the random integer that is generated.
example:
random integer generated: 10
the system should display a string that has a length of 10 character so either it will display the testNames1 or testNames2 because it has 10 character length
I tried doing this on my code, but it doesn't work.
<?php
function getName(){
$names = array(
'Juans',
'Luisss',
'Pedroaa',
'testNames1',
'testNames2',
'testName3',
'test', //This should not be return because im only generating a number random of 5-10 and this character has only 4 character length
'tse', //This should not be return because im only generating a number random of 5-10 and this character has only 3 character length
// and so on
);
$randomString = "";
for ($i = 0; $i <count($names); $i++) {
$value = rand(5,10);
$length_string = strlen($names[$i]);
if ($value == $length_string) {
return "name:".$names[$i].$value;
}
}
}
echo getName();
?>
Can anyone help me on how to do this?