PHPDaemon\Core\CallbackWrapper::removeFromArray PHP Method

removeFromArray() public static method

public static removeFromArray ( &$arr, $cb )
    public static function removeFromArray(&$arr, $cb)
    {
        if ($arr === null) {
            $arr = [];
            return false;
        }
        $e = static::extractCb($cb);
        foreach ($arr as $k => $item) {
            if (static::extractCb($item) === $e) {
                unset($arr[$k]);
                return true;
            }
        }
        return false;
    }

Usage Example

Example #1
0
 /**
  * Unbind event(s) or callback from event(s)
  * @param string|array $event Event name
  * @param callable     $cb    Callback, optional
  * @return this
  */
 public function unbind($event, $cb = null)
 {
     if ($cb !== null) {
         $cb = CallbackWrapper::wrap($cb);
     }
     is_array($event) or $event = [$event];
     $success = true;
     foreach ($event as $e) {
         if (!isset($this->eventHandlers[$e])) {
             $success = false;
             continue;
         }
         if ($cb === null) {
             unset($this->eventHandlers[$e]);
             continue;
         }
         CallbackWrapper::removeFromArray($this->eventHandlers[$e], $cb);
     }
     return $this;
 }
All Usage Examples Of PHPDaemon\Core\CallbackWrapper::removeFromArray