php - Create an attributes array => values ​without duplicates

I develop a module under prestashop and I retrieve from an API a list of articles with variations. here is the form of an article.
array:24 [в–ј
"is_default" => false
"options" => []
"_id" => "5dc40f2f8ec93f00089d2408"
"name" => "LONGONI noir Г scratch - Gant"
"full_price" => 21
"reference" => "1301100017"
"in_stock" => true,
"variations" => array:1 [в–ј
0 => array:3 [в–ј
"priority" => 0
"key" => "main"
"values" => array:2 [в–ј
0 => array:2 [в–ј
"priority" => 0
"value" => "droite"
]
1 => array:2 [в–ј
"priority" => 1
"value" => "gauche"
]
]
]
]
"declinations" => array:2 [в–ј
0 => array:10 [в–ј
"taxes" => array:1 [в–¶]
"id" => "k2oozxne"
"reference" => "1301100017DL"
"full_price" => 21
"in_stock" => true
"deprecated" => false
"test" => false
"ignore_stock" => true
"variations" => array:1 [в–¶]
"stock_quantity" => 0
]
1 => array:10 [в–ј
"taxes" => array:1 [в–¶]
"id" => "k2oozxnf"
"reference" => "1301100017GL"
"full_price" => 21
"in_stock" => true
"deprecated" => false
"test" => false
"ignore_stock" => true
"variations" => array:1 [в–¶]
"stock_quantity" => -1
]
]
]
inside each article there are "variations" I would like to be able to create a table including all the variations UNIQUE with the values ​​UNIQUE.
I started doing something like this which gets all the variations but without the values. I would like to be able to inject all the values ​​that correspond to the variations into it. Example:
main => [
'droite',
'gauche']
$attributes = [];
foreach ($articles as $article) {
if ($article['variations']) {
foreach ($article['variations'] as $key => $variation) {
$attrName = trim(str_replace(':', '', $variation['key']));
$attributes[] = $attrName;
}
}
}
dump(array_unique($attributes));
Thank you for your help.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: call to a member function update() on null
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.