What I Need
- i Need to create nesting array from existing array.
- if in array both values type are same .
- group according their type.
- like array[1] type is same array[2] type so i need to group them in single nested array.
here is the array structure
$data=$event['data']['pricing_detail'];
[1] => Array
(
[type] => General Public Tickets Adult
[amount] => 50
[comment] => (Working Days)
)
[2] => Array
(
[type] => General Public Tickets Adult
[amount] => 80
[comment] => (Saturday/ Sunday/ Holiday)
)
i need output like
[1] => Array ( [type] => General Public Tickets Adult [metadata]=>array ( [0] =>array ( [amount] => 50 [comment] => (Working Days) ) [1]=>array ( [amount] => 80 [comment] => (Saturday/ Sunday/ Holiday) ) ) )
code snippet
$data=$event['data']['pricing_detail'];
$metadata = array();
foreach($data as $key => $value)
{
if($value[1]['type'] == $value[2]['type'])
{
$metadata[$key]['amount'] = $value['amount'];
print_r($metadata);
}
else
{
echo "not matched";
}
}
- Problem im facing im not able to make logic so to get desired result.