issue with php shuffle multidimensional array -


hi there declare array variable , fill it:

foreach($urls $url)  {     $webs[] = array( 'name' => $url['name'],                      'url' => $url['link']); } 

it fill this:

$webs: ((name:cnn,'link:cnn.com/1')        (name:cnn,'link:cnn.com/1')        (name:cnn,'link:cnn.com/1')        (name:bbc,'link:bbc.com/1')        (name:bbc,'link:bbc.com/1')        (name:bbc,'link:bbc.com/1')) 

now want print it:

foreach($webs $web)  {         echo "<br/>".$web['name'].':'.$web['url']; } 

result:

cnn: cnn.com/1 cnn: cnn.com/2 cnn: cnn.com/3 bbc: bbc.com/1 bbc: bbc.com/2 bbc: bbc.com/3 

but not want it. want print result randomlay this:

bbc: bbc.com/1 cnn: cnn.com/1 bbc: bbc.com/3 cnn: cnn.com/3 cnn: cnn.com/2 cnn: cnn.com/3 bbc: bbc.com/2 

i try

$webs = shuffle($webs); foreach($webs $web)      {             echo "<br/>".$web['name'].':'.$web['url'];     } 

but no success error:

warning: invalid argument supplied foreach()  

note: in real code, $url['name'] array.

shuffle() true on success or false on failure when pass array on it, assigned true $webs in case. see more shuffle.

note: function assigns new keys elements in array. remove existing keys may have been assigned, rather reordering keys.

shuffle($webs); //see here cause shuffle return true or false foreach($webs $web)      {             echo "<br/>".$web['name'].':'.$web['url'];     } 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -