Let's says I have this array :
$numbers = array(1,2,3,4,5);
And this array :
$letters = array('A','B','C');
I want to put $letters
entries inside $numbers
randomly. I don't care about the order of $letters
, but I want $numbers
to keep the order. The goal is to have this kind of array :
$randomLettersInNumbers = array(1, 'B', 2, 3, 'A', 4, 'C', 5);
How can I achieve this ?
foreach($letters as $letter)
{
array_splice($numbers, rand(0, count($numbers)), 0, $letter);
}
print_r($numbers);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With