<?php
//Adult array start
$adult_array = Array
(
0 => Array
(
'travel_plan' => 'Business',
'premium_price' => 1336.81,
'eligibility' => 'Up to 75 Yrs',
'lower_limit' => 0,
'upper_limit'=> 75,
'no_travellers' => 2,
),
1 => Array
(
'travel_plan' => 'Holiday',
'premium_price' => 22960.81,
'eligibility' => 'Up to 75 Yrs',
'lower_limit' => 0,
'upper_limit' => 75,
'no_travellers' => 2
),
2 => Array
(
'travel_plan' => 'Schengen',
'premium_price' => 11740.81,
'eligibility' => 'Up to 75 Yrs',
'lower_limit' => 0,
'upper_limit' => 75,
'no_travellers' => 2
),
3 => Array
(
'travel_plan' => 'Student',
'premium_price' => 22960.81,
'eligibility' => 'Up to 30 Yrs',
'lower_limit' => 0,
'upper_limit' => 30,
'no_travellers' => 2
)
);
//Adult array end */
//Children array start
$children_array = Array
(
0 => Array
(
'travel_plan' => 'Student',
'premium_price' => 5740.205,
'eligibility' => 'Up to 30 Yrs',
'lower_limit' => 0,
'upper_limit' => 30,
'no_travellers' => 1
)
);
//Children array end
//Senior array start
$senior_array = Array
(
0 => Array
(
'travel_plan' => 'Senior',
'premium_price' => 38714.41,
'eligibility' => '76 to 85 Yrs',
'lower_limit' => 76,
'upper_limit' => 85,
'no_travellers' => 1
)
);
//Senior array end
$bigArray = array_merge($adult_array, $senior_array, $children_array);
$BusinessTravels = sortByTravelPlan('Business', $bigArray);
$StudentTravels = sortByTravelPlan('Student', $bigArray);
$SeniorTravels = sortByTravelPlan('Senior', $bigArray);
$SchengenTravels = sortByTravelPlan('Schengen', $bigArray);
$finalResult = array_merge($BusinessTravels, $StudentTravels, $SeniorTravels, $SchengenTravels );
print_r($finalResult);
function sortByTravelPlan($type, $bigArray){
$Array = [];
foreach ($bigArray as $key => $value) {
if($value['travel_plan'] == $type){
array_push($Array, $bigArray[$key]);
}
}
return processArray($Array);
}
function processArray($array){
$result = [];
$prev_price = null;
$max_age = null;
foreach ($array as $key => $value) {
$result['travel_plan'] = $value['travel_plan'];
if($value['premium_price'] > $prev_price){
$result['premium_price'] = $value['premium_price'];
}
}
$result['upper_limit'] = 30;
$result['lower_limit'] = 0;
$result['no_travellers'] = count($array);
return $result;
}
?>
- Output for git.master, git.master_jit, rfc.property-hooks
- Array
(
[travel_plan] => Schengen
[premium_price] => 11740.81
[upper_limit] => 30
[lower_limit] => 0
[no_travellers] => 1
)
This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.
Active branches
Archived branches
Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page
preferences:
160.31 ms | 405 KiB | 5 Q