因此,我使用以下數(shù)組傳入$record params,但當 API 的特定返回為 null 時出現(xiàn)錯誤。這是數(shù)組:$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條經(jīng)驗 獲得超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,
]);
- 1 回答
- 0 關(guān)注
- 125 瀏覽
添加回答
舉報
0/150
提交
取消