Stash::join_lists PHP Method

join_lists() public method

Create a union of two or more existing lists Lists *must* share the same keys and be *already in memory*
public join_lists ( ) : string
return string
    public function join_lists()
    {
        /* Sample use
           ---------------------------------------------------------
           {exp:stash:join_lists 
               name="my_combined_list"
               lists="list_1,list_2,list3"
           }
           --------------------------------------------------------- */
        // list names
        $lists = $this->EE->TMPL->fetch_param('lists');
        $lists = explode(',', $lists);
        // create an array of values
        $values = array();
        foreach ($lists as $name) {
            if (array_key_exists($name, $this->_stash)) {
                // ignore empty lists
                if (!empty($this->_stash[$name])) {
                    $values[] = $this->_stash[$name];
                }
            }
        }
        // implode values into the format of a delimited list, and set as the tagdata
        $this->EE->TMPL->tagdata = implode($this->_list_delimiter, $values);
        // set as a new variable
        return $this->set();
    }