我有10个包和2个基页用于结帐页面。我是否能够在if&中声明变量? elseif语句然后如果它们是真的则回显它们吗?
示例:
<?php
$package = $_POST['pack'];
if($pack == 1) {
$value = "item-1";
$value-2 = "gross-1";
} elseif ($pack == 2) {
$value = "item-2";
$value-2 = "gross-2";
} elseif($pack == 3) {
$value = "item-3";
$value-2 = "gross-3"; {
} elseif($pack == 4) {
$value = "item-4";
$value-2 = "gross-4";
} elseif($pack == 5) {
$value = "item-5";
$value-2 = "gross-5";
} else {
$value = 0;
$value-2 = 0;
}
<form action="PayPal">
<input value='<?php echo $value; ?>' name="whatever">
<input value='<?php echo $value; ?>' name="whatever-2">
</form>
所以基本上我需要根据一个真实的陈述来变量,所以它们可以在页面中回显以显示值。
任何提示?
答案 0 :(得分:0)
$package = $_POST['pack'];
if($pack == 1) {
$value = "item-1";
$value_2 = "gross-1";
} else if ($pack == 2) {
$value = "item-2";
$value_2 = "gross-2";
} else if($pack == 3) {
$value = "item-3";
$value_2 = "gross-3"; {
} else if($pack == 4) {
$value = "item-4";
$value_2 = "gross-4";
} else if($pack == 5) {
$value = "item-5";
$value_2 = "gross-5";
} else {
$value = 0;
$value_2 = 0;
}
<form action="PayPal">
<input value='<?php echo $value; ?>' name="whatever">
<input value='<?php echo $value_2; ?>' name="whatever_2">
</form>