Closed
Description
Hello,
Hereafter my sample
<!doctype html>
<html>
<body>
{$tab = array('A', 'B', 'C', 'D', 'E')}
<p>Before shuffle: {$tab|print_r}</p>
{$res = $tab|shuffle}
<p>After shuffle: {$tab|print_r}</p>
<p>Before adnShuffle: {$tab|print_r}</p>
{$new = $tab|adnShuffle}
<p>After adnShuffle: {$new|print_r}</p>
</body>
</html>
My result with smarty v5
Before shuffle: Array ( [0] => A [1] => B [2] => C [3] => D [4] => E ) 1
After shuffle: Array ( [0] => A [1] => B [2] => C [3] => D [4] => E ) 1
Before adnShuffle: Array ( [0] => A [1] => B [2] => C [3] => D [4] => E ) 1
After adnShuffle: Array ( [0] => B [1] => D [2] => E [3] => C [4] => A ) 1
It seems that the $tab variable is not modified after calling the php function shuffle
If I do a custom modifier, it works
function smarty_modifier_adnShuffle($iTab)
{
shuffle($iTab);
$new = array();
foreach($iTab as $e) {
$new[] = $e;
}
return $new;
}
Maybe because the shuffle parameter is a reference pointer?
Metadata
Metadata
Assignees
Labels
No labels