常规使用实例

<?php 
$like = "apple"; //定义 like 的值为 apple
$revariable = "relike_".$like; //定义重新变量
$relike_apple = "banana"; //定义重新的值
echo $like."<br>"; //apple
echo $revariable."<br>"; //relike_apple
echo $relike_apple."<br>"; //banana
echo $$revariable."<br>"; //banana
<?php
$like = "apple";
$apple = "banana";
echo $$like; //banana
<?php
$like = "apple"; $apple = "banana"; $banana = "orange";
echo $like; //apple 
echo $$like; //banana 
echo $$$like; //orange 
... 无限延续

表单对象实例

<form role="form" action="" method="post">
<select name="like" required>
	<option value=""> 我的选择</option>
	<option value="<?php $fruit = "Apple"; $Apple = "Banana"; $Banana = "Orange"; echo "$fruit" ?>"><?php echo $fruit; ?></option>
	<option value="<?php $car = "Benz"; $Benz = "BMW"; $BMW = "Audi"; echo "$car" ?>"><?php echo $car; ?></option>	
	<option value="<?php $city = "HongKong"; $HongKong = "Paris"; $Paris = "Tokyo"; echo "$city" ?>"><?php echo $city; ?></option>
</select>
  <input type="submit" value='Get My Like'>
</form>

<?php $name = $_POST['like']; echo $name; ?>;
<?php $name = $_POST['like']; echo $$name; ?>;
<?php $name = $_POST['like']; echo $$$name; ?>;

如果提交到新页面,需要在新页面补充相同的变量数据。

<?php $fruit = "Apple"; $Apple = "Banana"; $Banana = "Orange"; ?>
<?php $car = "Benz"; $Benz = "BMW"; $BMW = "Audi"; ?>
<?php $city = "HongKong"; $HongKong = "Paris"; $Paris = "Tokyo"; ?>

同时还支持以下句法规范:

<?php $fruit = "Apple"; $$fruit = "Banana"; $$$fruit = "Orange"; ?>
<?php $car = "Benz"; $$car = "BMW"; $$$car = "Audi"; ?>
<?php $city = "HongKong"; $$city = "Paris"; $$$city = "Tokyo"; ?>
分类: 前端开发

0 条评论

发表评论

Avatar placeholder

您的电子邮箱地址不会被公开。