I have some difficulties with PHP Arrays. I'm trying to foreach some values, order them with array_multisort and foreach them again so I can create some kind of code. So what I'm doing is, I'm passing json object as:
"options": [
{"key": "Ships From", "value": "Russia"},
{"key": "Color", "value": "Green"},
{"key": "Size", "value": "M"},
{"key": "Material", "value": "Flex"}
],
So this is received from frontend, and I'm foreaching them like so:
public function findAttribute($product_id, $values)
{
$array = array();
foreach ($values as $key => $value) {
$getAttr = $this->attribute($value['key']);
$getAttrValue = $this->attributeValue($getAttr->id, $value['value']);
$code = $getAttr['label'] . '=' . $getAttrValue['value'];
$collection = array_push($array, array($getAttr->default_order, $code));
}
array_multisort($array, SORT_ASC);
}
As you can see I have $getAttr and $getAttrValue, that selects values from database, in order to get default_order (integer) so I can sort them with multisort.
So actually this code works as expected, and when I write (after multisort) like:
foreach($array as $key => $value){
echo $value[1] .'/';
}
I have expected value, but when I call that function it gives me that it returns NULL, if I change echo to return, I have only first array. If I try like
foreach($array as $key => $value){
$code = $value[1] .'/';
}
return $code;
No success as well. What should I do?
array_search?