lib/PicoTwigExtension.php
public function mapFilter($var, $mapKeyPath)
    {
        if (!is_array($var) && (!is_object($var) || !($var instanceof Traversable))) {
            throw new Twig_Error_Runtime(sprintf(
                'The map filter only works with arrays or "Traversable", got "%s"',
                is_object($var) ? get_class($var) : gettype($var)
            ));
        }

        $result = array();
        foreach ($var as $key => $value) {
            $mapValue = $this->getKeyOfVar($value, $mapKeyPath);
            $result[$key] = ($mapValue !== null) ? $mapValue : $value;
        }
        return $result;
    }
public function mapFilter($var, $mapKeyPath)
    {
        if (!is_array($var) && (!is_object($var) || !($var instanceof Traversable))) {
            throw new Twig_Error_Runtime(sprintf(
                'The map filter only works with arrays or "Traversable", got "%s"',
                is_object($var) ? get_class($var) : gettype($var)
            ));
        }

        $result = array();
        foreach ($var as $key => $value) {
            $mapValue = $this->getKeyOfVar($value, $mapKeyPath);
            $result[$key] = ($mapValue !== null) ? $mapValue : $value;
        }
        return $result;
    }
public function mapFilter ( $ var , $ mapKeyPath ) { if ( ! is_array ( $ var ) && ( ! is_object ( $ var ) || ! ( $ var instanceof Traversable ) ) ) { throw new Twig_Error_Runtime ( sprintf ( 'The map filter only works with arrays or "Traversable", got "%s"' , is_object ( $ var ) ? get_class ( $ var ) : gettype ( $ var ) ) ) ; } $ result = array ( ) ; foreach ( $ var as $ key => $ value ) { $ mapValue = $ this -> getKeyOfVar ( $ value , $ mapKeyPath ) ; $ result [ $ key ] = ( $ mapValue !== null ) ? $ mapValue : $ value ; } return $ result ; }
Returns a array with the values of the given key or key path

This method is registered as the Twig `map` filter. You can use this
filter to e.g. get all page titles (`{{ pages|map("title") }}`).

@param array|Traversable $var        variable to map
@param mixed             $mapKeyPath key to map; either a scalar or a
array interpreted as key path (i.e. ['foo', 'bar'] will return all
$item['foo']['bar'] values)

@return array mapped values
Returns a array with the values of the given key or key path