I have foreach loop like:
foreach($attributes as $key => $value)
{
$option[] =["$value->name"=>"$value->value"]; //it is like ["color"=>"red"]
}
I want to merge $option[0], $option[1] and so on.... How to merge that ?
I tried:
for($i=1;$i<$count;$i++)
{
$option = array_merge($option[0],$option[$i]);
}
$option[$value->name] = $value->value;in foreach? This array will contain all key/value pairs of options.$option['color]is'red', Or, if you want to follow your approach, you can either declare a new array ($opt = []; foreach ($options as $value) $opt = array_merge($opt, $value);) or put the value in$option[0]instead of$option; or you can read these answers which have ways of flattening an array