You are here

public function TwigArray::shuffle in Bamboo Twig 8.5

Same name and namespace in other branches
  1. 8.2 bamboo_twig_extensions/src/TwigExtension/TwigArray.php \Drupal\bamboo_twig_extensions\TwigExtension\TwigArray::shuffle()
  2. 8.3 bamboo_twig_extensions/src/TwigExtension/TwigArray.php \Drupal\bamboo_twig_extensions\TwigExtension\TwigArray::shuffle()
  3. 8.4 bamboo_twig_extensions/src/TwigExtension/TwigArray.php \Drupal\bamboo_twig_extensions\TwigExtension\TwigArray::shuffle()

Shuffles an array.

Can't use the Twig filter callback cause the shuffle function is actually declared as a global function and not method of Twig_Extensions_Extension_Array.

Parameters

array|\Traversable $array: An array.

Return value

array|bool The shuffled array; or FALSE on failure.

File

bamboo_twig_extensions/src/TwigExtension/TwigArray.php, line 43

Class

TwigArray
Provides bridge for Array functions and filters.

Namespace

Drupal\bamboo_twig_extensions\TwigExtension

Code

public function shuffle($array) {
  if ($array instanceof \Traversable) {
    $array = iterator_to_array($array, FALSE);
  }
  shuffle($array);
  return $array;
}