Home >Backend Development >PHP Tutorial >Definition and function introduction of PHP
Definition and function introduction of PHP
PHP is a server-side scripting language, originally developed in 1994 by Rasmus Lerdorf. Its initials originally meant "Personal Home Page" and are now interpreted as "Hypertext Preprocessor". This language is mainly used in the field of web development. PHP is used in conjunction with HTML to create dynamic pages, process form data, connect to databases and other functions. The following will introduce some basic functions of PHP and provide specific code examples.
Example:
<?php $name = "Alice"; $age = 25; $height = 1.65; $isStudent = true; $fruits = array("apple", "banana", "orange"); ?>
Example:
<?php $grade = 85; if ($grade >= 60) { echo "及格"; } else { echo "不及格"; } for ($i = 1; $i <= 5; $i++) { echo $i . " "; } $num = 0; while ($num < 3) { echo $num . " "; $num++; } ?>
Example:
<?php function add($a, $b) { return $a + $b; } echo add(3, 5); // 输出8 ?>
Example:
<?php $servername = "localhost"; $username = "root"; $password = "password"; $dbname = "myDB"; // 创建连接 $conn = new mysqli($servername, $username, $password, $dbname); // 检查连接 if ($conn->connect_error) { die("连接失败: " . $conn->connect_error); } // 查询数据库 $sql = "SELECT id, name, age FROM students"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo "ID: " . $row["id"]. " - Name: " . $row["name"]. " - Age: " . $row["age"]. "<br>"; } } else { echo "0 结果"; } $conn->close(); ?>
The above is an introduction to some basic functions of PHP. As a powerful server-side scripting language, PHP is widely used in Web development. Hope the above content is helpful to you.
The above is the detailed content of Definition and function introduction of PHP. For more information, please follow other related articles on the PHP Chinese website!