Jamm\Memory\APCObject::select_fx PHP Method

select_fx() public method

Select from storage via callback function
public select_fx ( callable $fx, boolean $get_array = false ) : mixed
$fx callable ($value_array,$key)
$get_array boolean
return mixed
    public function select_fx($fx, $get_array = false)
    {
        $arr = array();
        $l = strlen($this->prefix);
        $i = new \APCIterator('user', '/^' . preg_quote($this->prefix) . '/', APC_ITER_KEY + APC_ITER_VALUE);
        foreach ($i as $item) {
            if (!is_array($item[self::apc_arr_value])) {
                continue;
            }
            $s = $item[self::apc_arr_value];
            $index = substr($item[self::apc_arr_key], $l);
            if ($fx($s, $index) === true) {
                if (!$get_array) {
                    return $s;
                } else {
                    $arr[$index] = $s;
                }
            }
        }
        if (!$get_array || empty($arr)) {
            return false;
        } else {
            return $arr;
        }
    }