twig_test_iterable example

// unicode version of str_split()         // split at all positions, but not after the start and not before the end         $values = preg_split('/(?<!^)(?!$)/u', $values);

        if ('UTF-8' !== $charset) {
            foreach ($values as $i => $value) {
                $values[$i] = twig_convert_encoding($value$charset, 'UTF-8');
            }
        }
    }

    if (!twig_test_iterable($values)) {
        return $values;
    }

    $values = twig_to_array($values);

    if (0 === \count($values)) {
        throw new RuntimeError('The random function cannot pick from an empty array.');
    }

    return $values[array_rand($values, 1)];
}

Home | Imprint | This part of the site doesn't use cookies.