Home > Backend Development > PHP Tutorial > PHP basic knowledge summarized by PHP newbies_PHP tutorial

PHP basic knowledge summarized by PHP newbies_PHP tutorial

WBOY
Release: 2016-07-13 17:34:14
Original
779 people have browsed it

After reading some basic knowledge of PHP, I summarized it here:

1. There are three ways to embed PHP scripts in HTML:

<scriptlanguage="php">
//嵌入方式一
echo("test");
</script>

<?
//嵌入方式二
echo"<br>test2";
?>

<?php
//嵌入方式三
echo"<br>test3";
?>
//Embedding method one
echo("test");
</script>

<?
//Embedding method two
<?
//这里是单行注释
PHP basic knowledge summarized by PHP newbies_PHP tutorial /*
这里是多行注释!可以写很多行注释内容
*/
?>
echo"<br>test2";
?> <?php
//Embedding method three
echo"<br>test3"; ?>

There is another embedding method, which is to use the same tag as Asp, but it requires modifying the relevant configuration of PHP.ini, which is not recommended.
2. PHP comments are divided into single-line and multi-line comments, which are the same as java comments.
<?
//This is a single line comment PHP basic knowledge summarized by PHP newbies_PHP tutorial
<?
$a=1;
functiontest(){
echo$a;
}
test();//这里将不能输出结果“1”。

functiontest2(){
global$a;
echo$a;
}
test2();//这样可以输出结果“1”。
?>
/* This is a multi-line comment! You can write many lines of comments */ ?> Be careful not to have nested comments, such as /*aaaa/*asdfa*/asdfasdfas*/. Such comments will cause problems. 3. There are 5 main data types in PHP, integer, double, string, array, object. 4. When calling external variables within a function, you need to declare them with global first, otherwise they will not be accessible. This is a difference between PHP and other programming languages. Case code:
<? $a=1; functiontest(){ echo$a; } test();//The result "1" will not be output here. functiontest2(){ global$a; echo$a; } test2();//This can output the result "1". ?>

Note: PHP can declare static variables inside functions. The usage is the same as in C language.

5. Variables of variables, functions of variables

<?
<?
//变量的变量
PHP basic knowledge summarized by PHP newbies_PHP tutorial PHP basic knowledge summarized by PHP newbies_PHP tutorial PHP basic knowledge summarized by PHP newbies_PHP tutorial PHP basic knowledge summarized by PHP newbies_PHP tutorial ?>

<?
//变量的函数

functionfunc_1(){
PHP basic knowledge summarized by PHP newbies_PHP tutorial }

functionfun($callback){
$callback();
}

PHP basic knowledge summarized by PHP newbies_PHP tutorial ?>
//Variables of variables
PHP basic knowledge summarized by PHP newbies_PHP tutorial PHP basic knowledge summarized by PHP newbies_PHP tutorial PHP basic knowledge summarized by PHP newbies_PHP tutorial
<?
$a[0]="abc";
$a[1]="def";

$b["foo"]=13;

$a[]="hello";//$a[2]="hello"
$a[]="world";//$a[3]="world"

$name[]="jill";//$name[0]="jill"
$name[]="jack";//$name[1]="jack"
?>
PHP basic knowledge summarized by PHP newbies_PHP tutorial ?> <? //Variable function functionfunc_1(){ PHP basic knowledge summarized by PHP newbies_PHP tutorial } functionfun($callback){ $callback(); } PHP basic knowledge summarized by PHP newbies_PHP tutorial ?> 6. PHP supports both scalar arrays and associative arrays. You can use list() and array() to create arrays. The array subscript starts from 0. Such as:
<? $a[0]="abc"; $a[1]="def"; $b["foo"]=13; $a[]="hello";//$a[2]="hello" $a[]="world";//$a[3]="world" $name[]="jill";//$name[0]="jill" $name[]="jack";//$name[1]="jack" ?>

7. Associated parameter transfer (use of &), two methods. Example:

<?
//Method 1:
functionfoo(&$bar){
PHP basic knowledge summarized by PHP newbies_PHP tutorial PHP basic knowledge summarized by PHP newbies_PHP tutorial
www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508486.htmlTechArticleAfter reading some basic knowledge of PHP, I will summarize it here: 1. There are three ways to embed PHP scripts in HTML : <scriptlanguage=php> //Embedding method: echo(test); </script> <? //Embedding...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template