Help with php random random array -


i need array problem have, far have this:

$array1 = array('foo1', 'foo2', 'foo3', 'foo4', 'foo5');  $array2 = array('newfoo1', 'newfoo2', 'newfoo3', 'newfoo4', 'newfoo5');  $random1 = array_rand($array2); $random2 = $array2[$random1];  foreach($array1 $key){  echo $key . '<br />';  echo $random2 . '<br /><br />'; } 

which outputs:

foo1 newfoo4  foo2 newfoo4  foo3 newfoo4  foo4 newfoo4  foo5 newfoo4 

but want "newfoo4" (array2) random item output somethng this:

foo1 newfoo3  foo2 newfoo4  foo3 newfoo1  foo4 newfoo5  foo5 newfoo2 

rather same,

but allow duplicates of array2 array1 , array2 not have have same amount items in arrays ....

so instance if array1 had 5 items , array 2 3 items end result output be:

foo1 newfoo3  foo2 newfoo1  foo3 newfoo3  foo4 newfoo2  foo5 newfoo3 

...i hope makes sense ...

$array1 = array('foo1', 'foo2', 'foo3', 'foo4', 'foo5'); $array2 = array('newfoo1', 'newfoo2', 'newfoo3', 'newfoo4', 'newfoo5');  foreach($array1 $key){     echo $key . '<br />';     echo $array2[array_rand($array2)] . '<br /><br />'; } 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -