繁体   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