mapdev\FacebookMessenger\Helper::array_find PHP Méthode

array_find() public static méthode

public static array_find ( $array, $key, null $default = null ) : mixed | null
$array
$key
$default null
Résultat mixed | null Used for easily finding values in a FB Callback response
    public static function array_find($array, $key, $default = null)
    {
        if (array_has($array, $key)) {
            return array_get($array, $key);
        } else {
            return $default;
        }
    }

Usage Example

 /**
  * Message constructor.
  * @param $message
  */
 public function __construct($message)
 {
     $this->mid = Helper::array_find($message, 'mid');
     $this->seq = Helper::array_find($message, 'seq');
     $this->isText = !is_null(Helper::array_find($message, 'text'));
     if ($this->isText) {
         $this->text = Helper::array_find($message, 'text');
         $this->quick_reply = Helper::array_find($message, 'quick_reply.payload', null);
         //drill straight to payload
         if (!is_null($this->quick_reply)) {
             $this->isQuickReply = true;
         }
     }
     $this->isSticker = !is_null(Helper::array_find($message, 'sticker_id'));
     if ($this->isSticker) {
         $this->sticker_id = Helper::array_find($message, 'sticker_id');
     }
     $this->hasAttachments = !is_null(Helper::array_find($message, 'attachments'));
     if ($this->hasAttachments) {
         $this->attachments = collect(Helper::array_find($message, 'attachments'))->map(function ($attachment) {
             return new Attachment($attachment);
         });
     }
     //TODO Add checkout update
 }
All Usage Examples Of mapdev\FacebookMessenger\Helper::array_find