isCli()) { $helper->log('This example should only be run from a Web Browser' . PHP_EOL); return; } $post = []; foreach (['category', 'quantity', 'fromUnit', 'toUnit'] as $value) { if (isset($_POST[$value])) { $post[$value] = StringHelper::convertToString($_POST[$value]); } } $categories = ConvertUOM::getConversionCategories(); $defaultCategory = $post['category'] ?? $categories[0]; $units = []; foreach ($categories as $category) { $categoryUnits = ConvertUOM::getConversionCategoryUnitDetails($category)[$category]; $categoryUnits = array_unique( array_combine( array_column($categoryUnits, 'unit'), array_column($categoryUnits, 'description') ) ); $units[$category] = $categoryUnits; } ?>

log('Quantity is not numeric'); } elseif (isset($post['category'], $units[$post['category']][$fromUnit], $units[$post['category']][$toUnit])) { /** @var float|string */ $result = ConvertUOM::CONVERT($quantity, $fromUnit, $toUnit); $helper->log("{$quantity} {$units[$post['category']][$fromUnit]} is {$result} {$units[$post['category']][$toUnit]}"); } else { $helper->log('Please enter quantity and select From Unit and To Unit'); } } else { $helper->log('Please enter quantity and select From Unit and To Unit'); }