Home > Backend Development > PHP Tutorial > PHP Language Basics 01 By ACReaper_PHP Tutorial

PHP Language Basics 01 By ACReaper_PHP Tutorial

WBOY
Release: 2016-07-14 10:12:17
Original
765 people have browsed it

1. Variables in PHP do not need to declare types. Variables are identified by $. The naming rules for variables also start with a letter or an underscore, followed by any character or underscore.

$PI = 3.14;
$radius = 5;
$cir = $PI * 2 * $radius;
2. Arrays in PHP. In fact, arrays in PHP are implemented using hash tables, so whether a string is used as an index or a number in PHP, the result of the essential mapping also corresponds to a number.
Secondly, you don’t need to write an index in PHP, for example, $test[] = 1.$test[] = 2; and so on. The default index starts from zero, with the latter index having an integer value one greater than the previous one.
Secondly, the print_r() function can be used to print the array.
3.Introduction to foreach. The so-called foreach is actually a loop
The syntax is foreach($array as [$key =>] [&]value){
code....
}
where as is the keyword. [] means optional, & means taking the address, otherwise value is just a copy of the corresponding value in the array.
4.list() function and array
list($var1,$var2,...) = array;
is equivalent to
$var1 = array[0];
$var2= array[1];
...
$varn = array[n - 1];
each($array) function, the value passed is an array, each function returns the current keyword/value pair and points the internal pointer to the next element. To put it bluntly, the each function returns an array. The each function returns an encapsulated array. This array has indexes 0, 1, key, and value. The value stored in the 0 index corresponds to the value stored in the key index. , and the value stored in the 1 index is the same as the value stored in value. Why should this be possible? This is to be used in conjunction with the list() function to implement list($k,$v) = $array; which is equivalent to $k = $array[0] and the stored value is equal to $array['key'];$v = The value stored in $array[1] is equal to the value of $array['value'];.
There is a pointer in the array type variable, which can be adjusted to point to an element in the array. So before each use of each, make sure it points to the first one, and you need to use the reset() function to reset it!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477212.htmlTechArticle1. Variables in PHP do not need to declare types. Variables are identified by $, and the naming rules for variables are also letters. Or start with an underscore, followed by any character or underscore. $PI = 3.14; $radius =...
Related labels:
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