I'm currently trying to create an associative array which will have two dimensions and I think a solution for this probleme could resolve problemes for array with more dimensions.
I recover data with an API which look like that :
{
"item_id": "89",
"name": "Confiture de Myrtilles",
"product_id": "737",
"meta_key": "vmm_warehouse_sg_10783",
"meta_value": "0"
},
{
"item_id": "89",
"name": "Confiture de Myrtilles",
"product_id": "737",
"meta_key": "vmm_warehouse_sg_10782",
"meta_value": "0"
},
{
"item_id": "91",
"name": "Poires Guyot (bio)",
"product_id": "690",
"meta_key": "_backorders",
"meta_value": "no"
},
{
"item_id": "91",
"name": "Poires Guyot (bio)",
"product_id": "690",
"meta_key": "_sold_individually",
"meta_value": "no"
},
I just want to create an array like this :
array[item_id->[meta_key->meta_value]]
So I have to recover the item_id which will have the role of the secondth array and after put in this array the meta_key and meta_value associated.
So for example I will have an array like this :
Products[89]["vmm_warehouse_sg_10783"->"0" "vmm_warehouse_sg_10782"->"0"]
And an other like this :
Products[91][........]
At the end, I will have a final array like this :
Products [ [89]->{"vmm_warehouse_sg_10783"->"0","vmm_warehouse_sg_10782"->"0"}
[91]->{.....}]
I have already tried something but I'm just a beginner and I don't found solution for my problem.
$Products = $this->wpdb->get_results( $SQL_Deliveries );
//this line allow $Products to recover all data from the API
foreach ( $Products as $Product ) {
$Meta_products[] = Product->item_id;
foreach($Product as $Product_meta){
$Meta_products[$item_id]->{Product_meta->meta_key,Product_meta
->meta_value);
}
I'm sure I did mitakes in my code too, but I really don't know how to resolve this problem. Thank you for your participation !