第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

php 回顯到新的 html 部分/標(biāo)簽

php 回顯到新的 html 部分/標(biāo)簽

PHP
白板的微信 2023-04-02 11:20:19
我在下面有這個(gè)表單代碼,它工作正常,但我想知道是否有更短的方法將結(jié)果回顯到 html 段落中。例如,我寧愿只說要回顯的函數(shù),而不命名構(gòu)成該函數(shù)的所有變量(例如,就像在最后的 p 標(biāo)記中所做的那樣)。<?php//variables and resultfunction bmi($height, $weight, $waist) {    $height = floatval($height);    $weight = floatval($weight);    $waist = floatval($waist);    return round($weight / ($height * $waist),1);}?><html><head>    <title>Test</title>    <meta name="viewport" content="width=device-width,initial-scale=1"></head><body><form action="" method="POST">   <h4>ABI 1</h4>    <input id="height" name="height" type="text" placeholder="height in meters or feet" value="<?php echo isset($_POST['height']) ? $_POST['height'] : ''; ?>" />    <br/>    <br/>    <input id="weight" name="weight" type="text" placeholder="weight in kgs or lbs" value="<?php echo isset($_POST['weight']) ? $_POST['weight'] : ''; ?>" />    <br/>    <br/>    <input id="waist" name="waist" type="text" placeholder="waist in inches or cm" value="<?php echo isset($_POST['waist']) ? $_POST['waist'] : ''; ?>" />    <br/>    <br/>    <input class="submit" type="submit" value="Submit"/>   <?php//handles if empty or 0 inputif (!empty($_POST['height']) && !empty($_POST['weight']) && ! empty($_POST['waist'])) : ?> <p id="result">Your score is <?php echo bmi($_POST['height'], $_POST['weight'],$_POST['waist']); endif;?></p>  </form></body></html>
查看完整描述

1 回答

?
嚕嚕噠

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超7個(gè)贊

你可以試試這個(gè)


//variables and result

function bmi() {

    foreach ($_POST as $name => $value) {

        switch ($name) {

            case 'height':

                $height = floatval($value);

                break;


            case 'weight':

                $weight = floatval($value);

                break;


            case 'waist':

                $waist = floatval($value);

                break;

        }

    }

    return round($weight / ($height * $waist),1);

}


<?php

//handles if empty or 0 input

if (!empty($_POST['height']) && !empty($_POST['weight']) && !

 empty($_POST['waist'])) : 


?>


 <p id="result">Your score is <?php echo bmi(); 


endif;

?>


查看完整回答
反對 回復(fù) 2023-04-02
  • 1 回答
  • 0 關(guān)注
  • 139 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號