Answer the question
In order to leave comments, you need to log in
How to shuffle a multidimensional array?
Hello, how to shuffle a given array:
Array(
[0]=>Array(
[title] => 'Title 1'
[description] => 'description here'
)
[1]=>Array(
[title] => 'Title 2'
[description] => 'description here'
)
[2]=>Array(
[title] => 'Title 3'
[description] => 'description here'
)
)
Array(
[0]=>Array(
[title] => 'Title 2'
[description] => 'description here'
)
[1]=>Array(
[title] => 'Title 3'
[description] => 'description here'
)
[2]=>Array(
[title] => 'Title 1'
[description] => 'description here'
)
)
Answer the question
In order to leave comments, you need to log in
I'm not sure what the question is, but I'll try to suggest the following:
function shuffle_assoc($list) {
if (!is_array($list)) return $list;
$keys = array_keys($list);
shuffle($keys);
$random = [];
foreach ($keys as $key)
$random[$key] = $list[$key];
return $random;
}
shuffle($arr);
https://www.php.net/manual/en/function.shuffle.php
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question