Ok, I’m very new to PHP. I will try my best to explain my question.
This is a var_dump of a json object.
What i am trying to do is access the information in the ‘register_sale_products’ object.
It contains product info like SKU, Price etc of the products in each sale. In the example below i am trying to list the SKU’s.
object(stdClass)[1]
public 'register_sales' =>
array
0 =>
object(stdClass)[2]
public 'id' => string '7c969b77-6825-bc65-3e04-64f922a570eb' (length=36)
public 'register_id' => string '07709f8e-8d90-11e0-8e09-4040f540b50a' (length=36)
public 'invoice_number' => string 'BH8464' (length=6)
public 'register_sale_products' =>
array
...
public 'totals' =>
object(stdClass)[6]
...
public 'register_sale_payments' =>
array
...
1 =>
object(stdClass)[9].......
I managed to get one SKU from the first “Product” object array ‘register_sale_products’ using this code.
$array = array() ;
foreach($data->register_sales as $sale){
$array = $sale->register_sale_products ;
}
foreach($array as $saleprod){
$details = explode(' / ', $saleprod->sku);
$result = $details[0];
}
echo $result;
I really need to get an a result of each object in the array.
Any help much appreciated.
You are overwriting
$resultevery time this loops:What you have to do is
echoinside the loop, let$resultbe a new array or let$resultbe a string which you append to: