function twig_get_array_keys_filter

Returns the keys for the given array.

It is useful when you want to iterate over the keys of an array:

<pre> {% for key in array|keys %} {# ... #} {% endfor %} </pre>

Parameters

array $array An array:

Return value

array The keys

1 string reference to 'twig_get_array_keys_filter'
Twig_Extension_Core::getFilters in drupal/core/vendor/twig/twig/lib/Twig/Extension/Core.php
Returns a list of filters to add to the existing list.

File

drupal/core/vendor/twig/twig/lib/Twig/Extension/Core.php, line 653

Code

function twig_get_array_keys_filter($array) {
  if (is_object($array) && $array instanceof Traversable) {
    return array_keys(iterator_to_array($array));
  }
  if (!is_array($array)) {
    return array();
  }
  return array_keys($array);
}