标签:
PHP没有创建变量的命令,变量会在首次赋值时进行创建。
简单样例
1
<?php
$word="My first choice";
$x=5;
echo $x;
echo "<br>";
echo $word;
?>
前面若要引用字符串则需要加. 否则会出现语法错误
<?php
$word="My first choice";
$x=5;
echo $x;
echo "<br>";
echo "This is " .$word;
?>
<DOCTYPE html>
<html>
<body>
<?php
$color="red";
echo "The color is" . $color."<br>";
?>
</body>
</html>
2.
<!DOCTYPE html>
<html>
<body>
<?php
$word="My first choice";
$x=5;
$y=6;
$z=$x+$y;
echo "This is " . $words ."<br>";
echo $z."<br>"
?>
</body>
</html>
3.
<!DOCTYPE html>
<html>
<body>
<?php
$x=5;
function myFunction()
{
$y=6;
echo "测试变量值" "<br>";
echo "x的值是" $x."<br>";
echo "y的值是" $y."<br>";
}
echo "测试变量值" "<br>";
echo "x的值是" $x."<br>";
echo "y的值是" $y."<br>";
?>
</body>
</html>
标签:
原文地址:http://www.cnblogs.com/teyues/p/5655626.html