src/Component/Json.php
/**
     * Removes intersections of a countable with another countable.
     *
     * @param mixed $value Comparing value. It will be treated as an array, and must not be a
     * resource.
     * @param bool $compareKeys To compute intersections in the keys or in the values.
     * @param ?string|int $index
     * @return self
     * @see https://gist.github.com/nunoveloso/1992851 Thanks to this.
     */
Removes intersections of a countable with another countable.
@param mixed $value Comparing value. It will be treated as an array, and must not be a
resource.
@param bool $compareKeys To compute intersections in the keys or in the values.
Removes intersections of a countable with another countable . @param mixed $value Comparing value . It will be treated as an array and must not be a resource . @param bool $compareKeys To compute intersections in the keys or in the values .
public function difference(
        $value,
        bool $compareKeys = false,
        $index = null
    ): self {
        $diff = function (array $array1, array $array2) {
            $diff = array();
            foreach ($array1 as $value) {
                $diff[$value] = 1;
            }
            foreach ($array2 as $value) {
                unset($diff[$value]);
            }
            return array_keys($diff);
        };
        $diffKey = function (array $array1, array $array2) {
            $diff = array();
            foreach ($array1 as $key => $value) {
                $diff[$key] = $value;
            }
            foreach ($array2 as $key => $value) {
                unset($diff[$key]);
            }
            return $diff;
        };
        $this->do(function (array &$array) use ($value, $compareKeys, $diff, $diffKey) {
            $value = (array)($this->decodeJsonIfNeeded($value));
            $array = $compareKeys ? $diff($array, $value) : $diffKey($array, $value);
        }, $index, true);
        return $this;
    }
public function difference ( $ value , bool $ compareKeys = false , $ index = null ) : self { $ diff = function ( array $ array1 , array $ array2 ) { $ diff = array ( ) ; foreach ( $ array1 as $ value ) { $ diff [ $ value ] = 1 ; } foreach ( $ array2 as $ value ) { unset ( $ diff [ $ value ] ) ; } return array_keys ( $ diff ) ; } ; $ diffKey = function ( array $ array1 , array $ array2 ) { $ diff = array ( ) ; foreach ( $ array1 as $ key => $ value ) { $ diff [ $ key ] = $ value ; } foreach ( $ array2 as $ key => $ value ) { unset ( $ diff [ $ key ] ) ; } return $ diff ; } ; $ this -> do ( function ( array & $ array ) use ( $ value , $ compareKeys , $ diff , $ diffKey ) { $ value = ( array ) ( $ this -> decodeJsonIfNeeded ( $ value ) ) ; $ array = $ compareKeys ? $ diff ( $ array , $ value ) : $ diffKey ( $ array , $ value ) ; } , $ index , true ) ; return $ this ; }
Removes intersections of a countable with another countable.
Removes intersections of a countable with another countable .