Jamm\Memory\Shm\SingleMemory::select_fx PHP Method

select_fx() public method

Select from memory elements by function $fx
public select_fx ( callable $fx, boolean $get_array = false ) : mixed
$fx callable
$get_array boolean
return mixed
    public function select_fx($fx, $get_array = false)
    {
        $this->readmemory();
        if (empty($this->mem[self::map_keys])) {
            return false;
        }
        $arr = array();
        foreach ($this->mem[self::map_keys] as $index => $s) {
            if (!is_array($s)) {
                continue;
            }
            if ($fx($s, $index) === true) {
                if (!$get_array) {
                    return $s;
                } else {
                    $arr[$index] = $s;
                }
            }
        }
        if (!$get_array || empty($arr)) {
            return false;
        } else {
            return $arr;
        }
    }