php实战开发之自我整理(学习笔记)

 

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>

 

posted @ 2016-07-09 12:41  小野猪  阅读(341)  评论(0编辑  收藏  举报