Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php // Load Carbon manually since we can't use Composer here use \Carbon\Carbon; if (!class_exists('Carbon\Carbon')) { require_once('https://cdn.jsdelivr.net/gh/briannesbitt/Carbon/src/Carbon/Carbon.php'); } $dobMinMaxAge = [ 'children_0m_6m' => [ 'min' => ['years' => 0, 'months' => 0, 'days' => 0], 'max' => ['years' => 0, 'months' => 0, 'days' => 180], ], 'children_6m_3y' => [ 'min' => ['years' => 0, 'months' => 0, 'days' => 180], 'max' => ['years' => 3, 'months' => 0, 'days' => 0], ], 'children_3y_6y' => [ 'min' => ['years' => 3, 'months' => 0, 'days' => 0], 'max' => ['years' => 6, 'months' => 0, 'days' => 0], ], 'adolescent_boy' => [ 'min' => ['years' => 6, 'months' => 0, 'days' => 0], 'max' => ['years' => 20, 'months' => 0, 'days' => 0], ], 'adolescent_girl' => [ 'min' => ['years' => 6, 'months' => 0, 'days' => 0], 'max' => ['years' => 20, 'months' => 0, 'days' => 0], ], 'lactating_mother' => [ 'min' => ['years' => 16, 'months' => 0, 'days' => 0], 'max' => ['years' => 100, 'months' => 0, 'days' => 0], ], 'pregnant_woman' => [ 'min' => ['years' => 16, 'months' => 0, 'days' => 0], 'max' => ['years' => 100, 'months' => 0, 'days' => 0], ], ]; // Use simple DateTime instead of Carbon for online PHP testing $dob = new DateTime("2022-04-30"); $now = new DateTime(); $beneficiary_type = "children"; if ($beneficiary_type == 'children') { foreach ($dobMinMaxAge as $type => $range) { $minDate = clone $now; $minDate->sub(new DateInterval("P{$range['max']['years']}Y{$range['max']['months']}M{$range['max']['days']}D")); $maxDate = clone $now; $maxDate->sub(new DateInterval("P{$range['min']['years']}Y{$range['min']['months']}M{$range['min']['days']}D")); if ($dob >= $minDate && $dob <= $maxDate) { $beneficiary_type = $type; break; } } if (strpos($beneficiary_type, 'children_') !== 0) { echo "error\n"; exit; } } echo "Min Date: " . $minDate->format('Y-m-d') . "\n"; echo "Max Date: " . $maxDate->format('Y-m-d') . "\n"; echo "Beneficiary Type: " . $beneficiary_type . "\n";
Copy Clear