【PHP】 基础语法,自学笔记(二)
基本语法
- 输出
echo 'hello php<br>';
- 注释:跟
Html
的写法一样,- 有
//
单行注释 - 有多行注释
/**
- 有
Php
文件里也可以放HTML
的东西
变量声明
基础
字符变量,数,布尔,以及 null
,输出的结果如下
数字运算
基本的加、减、乘、除、取余、以及幂运算
自增,自减
Get & Post 请求
这个是 Get
请求,会把参数放到 URL
中
这个是 Post
请求,这里的 form method
要改变,而且 $_POST
也要配合支持
获取 input
框中的的参数并计算,处理后返回给页面
数组语法
代码
基础
<?php
// 声明变量
$name = "Ruby";
$food = "BBQ";
// 整数,浮点数
$age = 18;
$price = 9.9;
$count = 3;
$sum = $price * $count;
// 布尔
$is_sunny_day = true;
$is_rain_day = false;
// null
$total = null;
echo "Today i spend ¥{$total} money <br>"; // null 为空
echo "Hello {$name} <br>";
echo "I like {$food} <br>";
echo "I'm {$age} years old <br>";
echo "BBQ's price is ${$price} <br>";
echo "BBQ's price is \${$price} <br>";
echo "today is a lovely sunny day? {$is_sunny_day} <br>"; // 布尔 true 会转换成数字1
echo "today is not a lovely sunny day? {$is_rain_day} <br>"; // 布尔 false 不显示
$total = $count * $price;
echo "Today i spend ¥{$total} money <br>";
数字
<?php
$x = 2;
$y = 3;
$z = null;
echo "{$z} <br>";
echo "x: {$x}, y: {$y} <br>";
$z = $x + $y;
// $z = $x - $y;
// $z = $x * $y;
// $z = $x / $y;
// $z = $x ** $y;
echo "{$z}<br>";
$count = 2;
echo "count:>> {$count}<br>";
$count++;
echo "count:>> {$count}<br>";
$count--;
echo "count:>> {$count}<br>";
$count+=3;
echo "count:>> {$count}<br>";
$count-=2;
echo "count:>> {$count}<br>";
$count*=3;
echo "count:>> {$count}<br>";
$count/=2;
echo "count:>> {$count}<br>";
GET & POST 请求
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="index.php" method="get">
<label>姓名:</label><br>
<input type="text" name="username"><br>
<label>密码:</label><br>
<input type="password" name="password"><br>
<input type="submit" value="提交">
</form>
</body>
<script>
</script>
</html>
<?php
echo $_GET["username"] . "<br>"; // 换行的方式
echo $_GET["password"];
洗脚代码
<!DOCTYPE html>
<html lang="en">
<body>
<form action="index.php" method="post">
<label>洗脚次数:</label><br>
<input type="text" name="quantity"><br>
<input type="submit" value="提交">
</form>
</body>
<script>
</script>
</html>
<?php
$price = 998;
$quantity = $_POST['quantity'];
echo "您已经洗了" . $quantity . "次脚,共需支付" . $price * $quantity . "元。";
原文地址:https://blog.csdn.net/u010263423/article/details/144005754
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!