簡體   English   中英

數組未返回給定鍵的值

[英]array is not returning value for given key

我正在使用以下PHP代碼...

$settings[] = get_app_settings();
echo $settings['weight_unit'];

但其拋出錯誤“未定義索引”。

而當我做print_r($settings); 它產生以下...

Array ( [0] => Array ( [support_email] => info@domain.com [support_phone] => 9812345678 [currency_symbol] => $ [weight_unit] => g. [catalogue_image_width] => 450 [catalogue_image_height] => 675 [single_product_image_width] => 500 [single_product_image_height] => 500 [product_image_width] => 200 [product_image_height] => 200 [tax_rate] => 1 [shipping_charges] => 0 ) ) 

為什么不返回$settings['weight_unit'];

解決方法是從$settings刪除[] (數組)。 不管怎么說,多謝拉。

嘗試$settings = get_app_settings(); -您可能希望直接分配返回的數組,而不要分配給$settings的新數組元素。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM