How would I shuffle this type of array structure?
<?php
$array['name'] = 'value1';
$array['name'] = 'value2';
$array['name'] = 'value3';
$array['name'] = 'value4';
$array['name'] = 'value5';
?>
How would I shuffle this type of array structure?
<?php
$array['name'] = 'value1';
$array['name'] = 'value2';
$array['name'] = 'value3';
$array['name'] = 'value4';
$array['name'] = 'value5';
?>
Well, since the result of your code would be a single-element array with that element having a key of "name" and a value of "value5", there's no reason to shuffle it. I suspect you have something else in mind, perhaps?
How would I shuffle the values from the key called 'name'?
I just did this for a quick fix.
$ar = array('1','2','3');
shuffle($ar);
$array['name'] = $ar[0];
I'm still not getting what you want to do. An array can only have one element per given key, so there can be only one element of array with the key called "name". In other words, this...
<?php
$array = array('name'=>'value1', 'name'=>'value2', 'name'=>'value3');
print_r($array);
?>
...will output this...
Array ( [name] => value3 )
I like using
$array['name'] = $ar[0];
format because it's easier for me to read all the long arrays. I wanted to somehow shuffle the value so the output won't always be value3.
Thanks for explaining the array more in detail.