View Code Snippet [PHP]

Generate Height

                                    public function height() {
    $heights = [];

    for ($ft = 4; $ft <= 7; $ft++) {
        for ($inch = ($ft == 4 ? 5 : 0); $inch < ($ft == 7 ? 1 : 12); $inch++) {
            $height_inch = $ft + ($inch / 12);
            $height_inch_text = "$ft ft $inch inch";
            $height_cm = $height_inch * 30.48; // 1 foot = 30.48 cm
            $height_cm_text = round($height_cm, 2) . " cm";

            $heights[] = [
                'height_inch' => $height_inch,
                'height_inch_text' => $height_inch_text,
                'height_cm' => $height_cm,
                'height_cm_text' => $height_cm_text
            ];
        }
    }

    // Print the array for verification
    echo "
";
    print_r($heights);
    echo "
"; }