First understanding of PHP (1) Basic syntax, first understanding of php basic syntax _ PHP Tutorial

Source: Internet
Author: User
First understanding of PHP (1) Basic syntax, first understanding of php basic syntax. I first got to know the basic syntax of PHP (I). I first got to know the basic syntax of php and was always ready to learn PHP. as a result, there was always a problem some time ago, which was delayed for a while. Catch up now! This series only talks about basic PHP (1) and basic php syntax.

I have been preparing to learn PHP, but there was always a problem some time ago, which was delayed for a while. Catch up now!

This series only talks about some of my views on PHP, not the nature of the tutorial. In addition, I am a little white, just write casually, please Pat. I have studied c, java, python, and HTML. If you have similar experience with me and want to contact PHP friends, it would be better to provide you with some ideas.

In my opinion, PHP has a strong HTML style and is born for web programming. One of the biggest features is how variables are used. In c, python, and other languages, a variable is called directly by writing a few characters, such as the classic for (I = 0; I <50; I ++ ). However, PHP is closer to HTML in variable processing. directly written characters are considered strings. to use a variable, you must start with $: for ($ I = 0; $ I <50; $ I ++), which makes it difficult for me to write, however, when I see the processing of strings, I find the following benefits:

The concatenation of strings in PHP can be performed like using "," in python, for example:

$ A = 'Bob ';
Echo "Hello", $;

The result is as follows:

$ A = 'Bob ';
Echo "Hello". $;

The results are the same:

$ A = 'Bob ';
Echo "Hello $ ";

The results are still the same:

 

This is the unique PHP style.

Another feature is the array in PHP. PHP array. In my opinion, PHP arrays are a collection of python lists and dictionaries. For the stored data, unlike the c array, the data type needs to be declared. both integer and string types can be stored in the same array in a hybrid manner "; at the same time, it not only supports the indexing of traditional arrays by serial numbers starting from 0, but also supports the indexing of strings, which in turn misses the python dictionary. In short, it is a very strange thing, but it is very convenient to think carefully.

$ Arr = array (0 => 50, 'G' => 'GGG ', 1 => 'WWW', 'H' => 'hhh ');
Print_r ($ arr );

For example, arr is an array with four elements. The value 0 indicates an integer of 50. the next element is the string ggg, which is indexed by the character "g". The third element is the string www; the fourth element is the string hhh, which is indexed by the character "h.

Next, use the array_push function to append a string element www to the end of the array.

$ Arr = array (0 => 50, 'G' => 'GGG ', 1 => 'WWW', 'H' => 'hhh ');
Array_push ($ arr, 'WWW ');
Print_r ($ arr );

For example, although the appended element is the fifth element, it is still sorted using index 2.

This is how I feel about the basic PHP syntax.

Summary (1) Basic syntax: I have been familiar with php basic syntax and have been preparing to learn PHP. as a result, there was always something that was delayed for a while. Catch up now! This series is just about...

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.