亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從 API 輸出空字符串

從 API 輸出空字符串

PHP
呼喚遠方 2023-04-02 10:51:53
因此,我使用以下數組傳入$record params,但當 API 的特定返回為 null 時出現錯誤。這是數組:$office->load([    'post_title' => $record->office,    'location_id' => $record->location_id,    'location' => $record->location,    'business_unit' => $record->business_unit,    'type_id' => $record->type_id,    'brand_id' => $record->brand_id,]);我的$record->brand_id返回為 null 并且它使我的整個腳本崩潰,有沒有一種方法可以將 null 輸出為字符串并將 $record->brand_id 包裝在某些東西中?更新:我最終配置了所需的東西brand_id,因為$record->brand_id ?? $default_value效果很好!
查看完整描述

1 回答

?
茅侃侃

TA貢獻1842條經驗 獲得超21個贊

如果您知道哪些值可能null對 API 輸出沒有影響,您可以嘗試檢查空值的運算符,例如null coalescing operator (??).


$default_value = 'default';


$office->load([

    'post_title' => $record->office,

    'location_id' => $record->location_id,

    'location' => $record->location,

    'business_unit' => $record->business_unit,

    'type_id' => $record->type_id,

    'brand_id' => $record->brand_id ?? $default,

]);


查看完整回答
反對 回復 2023-04-02
  • 1 回答
  • 0 關注
  • 128 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號