First understanding of PHP (1) basic syntax, first understanding of php basic 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.