Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php shuffle doesn't work in smarty v5 #1096

Open
criocere opened this issue Jan 2, 2025 · 0 comments
Open

php shuffle doesn't work in smarty v5 #1096

criocere opened this issue Jan 2, 2025 · 0 comments

Comments

@criocere
Copy link

criocere commented Jan 2, 2025

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant