简体   繁体   中英

How to get specific array values from moltin get a product

I just started using moltin and learn to developing it. In the getting started there is code that to show product

<?php
$product = \Product::Find(['slug' => 'baju']);
?>

documentation link https://moltin.com/getting-started/php

and the result is when I print array

<?php
print_r($product);
?>

It shows like this

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 

How to get specific array from this list? I already try

<?php
echo $product[0]['id'];
?>

it didn't work, show error Notice: Undefined offset: 0

试试这个:

echo $product['result'][0]['id'];

you have a multidimensional array under the result key

access it the following way:

$product['result'][0]['id']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM