php基础语法
<?php
header(`content-type:text/html;charset="utf-8"`);
echo "<h1>hello world</h1>";
echo("<h1>hello world</h1>");
print_r("<h1>hello world</h1>");
var_dump(100);
var_dump("hello");
$username = "falcon";
$age = 18;
echo "我是".$username.",今年".$age."岁<br/>";
echo "我是{$username},今年{$age}岁";
$isYes = true;
if($isYes){
echo "是";
}else{
echo "否";
}
$num = 2;
switch($num){
case 1:
echo "数字1";break;
case 2:
echo "数字2";break;
default:
echo "错误";break;
}
for ($i = 0;$i < 5;$i++){
echo "下标".$i."<br/>";
}
function printHello(){
print "hello world<br/>";
}
printHello();
$cars = array("大众","别克","现代");
var_dump($cars);
echo $cars[1];
for($i = 0;$i < count($cars);$i++){
echo "下标:{$i},数据:{$cars[$i]}<br/>";
}
$arr = array("falcon" => "前端工程师","lily"=>"后端工程师","alice"=>"软件测试工程师");
var_dump($arr);
foreach($arr as $key => $value){
echo "下标:{$key},数据:{$value}<br/>";
}
$arr = array{
array("name" => "falcon","english" => "100","math" => "80"),
array("name" => "lily","english" => "90","math" => "90"),
array("name" => "alice","english" => "60","math" => "70")
};
for($i = 0;$i < count($arr);$i++){
var_dump($arr[$i]."<br/>");
}
echo $arr[2]["math"];
PHP链接数据库
<?php
header("content-type:text/html;charset=utf-8");
$link = mysql_connect("localhost","root","root");
if($link){
echo "链接失败";
exit;
}
mysql_set_charset("utf-8");
mysql_select_db("falcon");
$sql = "SELECT * FROM info";
$res = mysql_query($sql);
echo "<table border = '1'>"
echo "<th>学号</th><th>姓名</th><th>语文</th><th>数学</th><th>英语</th>"
whiele(row = mysql_fetch_assoc($res)){
echo "<tr><td>{$row['id']}</td><td>{$row['name']}</td><td>{$row['chinese']}</td><td>{$row['math']}</td><td>{$row['english']}</td></tr>
}
echo "</table>";
mysql_close($link);
?>