PHP language basics 01 By ACReaper

Source: Internet
Author: User

1. Variables in PHP do not need to be declared. the variables are identified by $. The naming rules of variables start with a letter or underline, followed by any character or underline. $ PI = 3.14; $ radius = 5; $ cir = $ PI * 2 * $ radius; 2. in PHP, arrays in PHP are actually implemented using hash tables. Therefore, no matter the string is used as the index or the number is mapped in PHP, The result corresponds to a number. In PHP, indexes can be left blank, for example, $ test [] = 1. $ test [] = 2. The default index starts from scratch, and the last one is greater than the integer of the previous one. Secondly, the print array can be printed using the print_r () function. 3. Introduction to foreach. The so-called foreach is actually a loop syntax for foreach ($ array as [$ key =>] [&] value) {code...} Where as is the keyword. [] Indicates optional, & indicates the address. Otherwise, the value is only a copy of the corresponding value of the array. 4. list () function and array list ($ var1, $ var2 ,...) = array; equivalent to $ var1 = array [0]; $ var2 = array [1];... $ varn = array [n-1]; each ($ array) function. The passed value is an array. The 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, and the each function returns an encapsulated array with indexes 0, 1, key, and value, the value of the 0 index is the same as that of the key index, while the value of the 1 index is the same as that of the value. Why? This is used with the list () function to implement list ($ k, $ v) = $ array; that is, it is equivalent to $ k = $ array [0] and the value is equal to $ array ['key']; $ v = $ array [1] The stored value is equal to the value of $ array ['value. An array variable has a pointer that can be adjusted to point to an element in the array. Therefore, before using each time, make sure it points to the first one. You need to use the reset () function to reset it!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.