[英]array is not returning value for given key
I am using the following PHP code... 我正在使用以下PHP代码...
$settings[] = get_app_settings();
echo $settings['weight_unit'];
but its throwing error 'undefined index'. 但其抛出错误“未定义索引”。
and when i do print_r($settings);
而当我做
print_r($settings);
it generates following... 它产生以下...
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 ) )
Why is it not returning a value for $settings['weight_unit'];
为什么不返回
$settings['weight_unit'];
? ?
its solved by removing []
(array) from $settings
. 解决方法是从
$settings
删除[]
(数组)。 thanks anyways. 不管怎么说,多谢拉。
Try $settings = get_app_settings();
尝试
$settings = get_app_settings();
- you probably want to assign the returned array directly and not to a new array element in $settings
. -您可能希望直接分配返回的数组,而不要分配给
$settings
的新数组元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.