public static function filter_data(&$data, $filterArr, $method = null, $add = false)
    {
        if ($method === null) {
            $method = 'keep';
        }

        foreach ($data as $k => $v) {
            if (($method == 'remove' && in_array($k, $filterArr))
             || ($method == 'keep' && !in_array($k, $filterArr))
            ) {
                if (is_array($data)) {
                    unset($data[$k]);
                } elseif (is_object($data)) {
                    unset($data->$k);
                }
            }
        }

        if (!empty($add)) {
            $data = self::merge_data($data, $add);
        }

        return $data;
    }
public static function filter_data(&$data, $filterArr, $method = null, $add = false)
    {
        if ($method === null) {
            $method = 'keep';
        }

        foreach ($data as $k => $v) {
            if (($method == 'remove' && in_array($k, $filterArr))
             || ($method == 'keep' && !in_array($k, $filterArr))
            ) {
                if (is_array($data)) {
                    unset($data[$k]);
                } elseif (is_object($data)) {
                    unset($data->$k);
                }
            }
        }

        if (!empty($add)) {
            $data = self::merge_data($data, $add);
        }

        return $data;
    }
public static function filter_data ( & $ data , $ filterArr , $ method = null , $ add = false ) { if ( $ method === null ) { $ method = 'keep' ; } foreach ( $ data as $ k => $ v ) { if ( ( $ method == 'remove' && in_array ( $ k , $ filterArr ) ) || ( $ method == 'keep' && ! in_array ( $ k , $ filterArr ) ) ) { if ( is_array ( $ data ) ) { unset ( $ data [ $ k ] ) ; } elseif ( is_object ( $ data ) ) { unset ( $ data -> $ k ) ; } } } if ( ! empty ( $ add ) ) { $ data = self :: merge_data ( $ data , $ add ) ; } return $ data ; }
Filters entries of an array.

@param string $data      the source
@param array  $filterArr Array of keys keys that should be removed or kept.
@param string $method    'remove' deletes all $filterArr keys from $data,
'keep' deletes all keys that are not in $filterArr
@param array $add        optional array of values to be added to $data
@return array|object
Filters entries of an array .