Anyone can help me about multi dimensional arrays? I have an array that wanted to random arrays inside it, so therefore its hierarchy or there index value will be changed and different from the original arrangement of arrays, like:
This is the original arrays
Array(
[0]=>Array(
[title] => 'Title 1'
[description] => 'description here'
)
[1]=>Array(
[title] => 'Title 2'
[description] => 'another description here'
)
[2]=>Array(
[title] => 'Title Here Again'
[description] => 'description here again'
)
)
That will be the original structure of the array above, and if you random it, let say this will be the outcome
This is the random-ed arrays
Array(
[0]=>Array(
[title] => 'Title 2'
[description] => 'another description here'
)
[1]=>Array(
[title] => 'Title 3'
[description] => 'another description again'
)
[2]=>Array(
[title] => 'Title 1'
[description] => 'description here'
)
)
As you can see, values inside the arrays are being randomize at different positions, now the problem is i can't get the exact logic on how to get the original array index like this -> ( [0] ) from randomized arrays. Like the value 'Title 1' its original index is [0], and after it was random-ed it became [2] but still i wanted 'Title 1' being assigned to index [0]. Here's a short php code on how i randomized the arrays:
foreach (shuffleThis($rss->getItems()) as $item) {
foreach($item as $key=>$value){
if($key=='title'){
$title=$value;
}
if($key=='description'){
$description=$value;
}
}
}
function shuffleThis($list) {
if (!is_array($list)) return $list;
$keys = array_keys($list);
shuffle($keys);
$random = array();
foreach ($keys as $key) {
$random[] = $list[$key];
}
return $random;
}
Just wanted to get they keys original array index from being random-ed.
Thanks!