Как в callback функцию preg_replace_callback передать массив?

Есть код обработки шаблона

$info_ids = array(1,2,3,4,5);
                    if (strpos($tpl_card_discounts_element->result['content'], "[type=") !== false) {
                        $tpl_card_discounts_element->result['content'] = preg_replace_callback("#\\[(type)=(.+?)\\](.*?)\\[/type\\]#is", 'benefits_check_card_discounts_element', $tpl_card_discounts_element->result['content']);
                    }

Так же есть callback функция

                    function benefits_check_card_discounts_element($matches = array())
                    {
                        $data_in_tpl = $matches[2];
                        $block = $matches[3];

                        if ($matches[1] == "type") $action = 1; else $action = 0;

                        $data_in_tpl = str_replace(" ", "", $data_in_tpl);
                        $data_in_tpl = explode(',', $data_in_tpl);
                        $found = false;

                        foreach ($info_ids as $element) {
                            if ($action == 1) {
                                if (in_array($element, $data_in_tpl)) {
                                    return $block;
                                }
                            } else {
                                if (in_array($element, $data_in_tpl)) {
                                    $found = true;
                                }
                            }
                        }

                        if ($action == 0 AND !$found) {
                            return $block;
                        }
                        return "";
                    }

в которой есть перенная-массив $info_ids, которую как-то надо в функцию передать. Я не могу её передать через global, т.к. у меня цикл и значение $info_ids нужно передавать каждый раз.

Есть ли варианты?


Ответы (0 шт):