View Code Snippet [PHP]

Generate Weight

                                    private function generateWeightArray($start_kg, $end_kg) {
        $weights = array();

        // Iterate through each kilogram weight from start to end
        for ($kg = $start_kg; $kg <= $end_kg; $kg++) {
            // Convert kilograms to pounds
            $pounds = $kg * 2.20462; // 1 kilogram = 2.20462 pounds

            // Add weight information to the array
            $weight_info = array(
                'weight_kg' => $kg,
                'weight_kg_unit' => 'kg',
                'weight_pound' => round($pounds, 2), // Round to 2 decimal places
                'weight_pound_unit' => 'lbs'
            );

            // Add weight information to the array
            $weights[] = $weight_info;
        }

        return $weights;
    }