我刚开始使用moltin并学会开发它。 在开始时,有代码显示产品
<?php
$product = \Product::Find(['slug' => 'baju']);
?>
文档链接https://moltin.com/getting-started/php
,结果是我打印数组
<?php
print_r($product);
?>
它显示如下
Array ( [status] => 1 [result] => Array ( [0] => Array ( [id] => 1207658536885027482 [order] => [created_at] => 2016-03-17 03:08:58 [updated_at] => 2016-03-17 03:08:58 [sku] => baju-1 [title] => baju [slug] => baju [sale_price] => 0 [status] => Array ( [value] => Live [data] => Array ( [key] => 1 [value] => Live ) ) [category] => Array ( [value] => Uncategorized [data] => Array ( [1134518259857490806] => Array ( [id] => 1134518259857490806 [order] => [created_at] => 2015-12-07 05:12:15 [updated_at] => 2015-12-07 05:12:15 [parent] => [slug] => uncategorized [status] => Array ( [value] => Live [data] => Array ( [key] => 1 [value] => Live ) ) [title] => Uncategorized [description] => Products that do not fit into another category ) ) ) [stock_level] => 10 [stock_status] => Array ( [value] => In Stock [data] => Array ( [key] => 1 [value] => In Stock ) ) [description] => baju [requires_shipping] => Array ( [value] => Yes [data] => Array ( [key] => 1 [value] => Yes ) ) [weight] => 0 [height] => 0 [width] => 0 [depth] => 0 [catalog_only] => Array ( [value] => No [data] => Array ( [key] => 0 [value] => No ) ) [tax_band] => Array ( [value] => Default [data] => Array ( [id] => 1134518260142703561 [title] => Default [description] => [rate] => 20 [created_at] => [updated_at] => ) ) [collection] => [brand] => [price] => Array ( [value] => £1.20 [data] => Array ( [formatted] => Array ( [with_tax] => £1.20 [without_tax] => £1.00 [tax] => £0.20 ) [rounded] => Array ( [with_tax] => 1.2 [without_tax] => 1 [tax] => 0.2 ) [raw] => Array ( [with_tax] => 1.2 [without_tax] => 1 [tax] => 0.2 ) ) ) [is_variation] => [modifiers] => Array ( ) [images] => Array ( ) ) ) [pagination] => Array ( [total] => 1 [current] => 1 [limit] => 10 [offset] => 0 [from] => 1 [to] => 1 [offsets] => Array ( [first] => [previous] => [next] => [last] => ) [links] => Array ( [first] => [previous] => [next] => [last] => ) ) ) status = 1
如何从此列表中获取特定数组? 我已经尝试了
<?php
echo $product[0]['id'];
?>
它不起作用,显示错误注意:未定义的偏移量:0
答案 0 :(得分:1)
尝试一下:
echo $product['result'][0]['id'];
答案 1 :(得分:1)
您在result
键
按以下方式访问它:
$product['result'][0]['id']