Home > Article > Backend Development > First introduction to PHP (1) basic syntax, first introduction to basic syntax of PHP_PHP tutorial
I have been preparing to learn PHP, but something happened some time ago, which delayed me for a while. Now hurry up and catch up!
This series is just about some of my views on PHP, it is not a tutorial. In addition, I am a novice, I just write essays, please give me a pat. I have studied c, java, python, and have been exposed to some HTML. It would be great if friends who have similar experience to me and want to get into PHP can provide you with some ideas.
In my opinion, PHP has a strong HTML style, and it is indeed born for web programming. One of the biggest features is the way variables are used. In languages such as C and Python, a variable is called directly by writing the name with a few characters, such as the classic for (i=0;i<50;i). However, PHP is closer to HTML in the way it handles variables. Directly written characters will be considered strings. If you want to use variables, you need to start with $: for($i=0;$i<50;$ i) This makes me very uncomfortable, and I think it will be troublesome to write like this, but after seeing the processing of strings, I found that this has such benefits:
String concatenation in PHP can be done using "," like Python, such as:
$a='Bob';
echo "Hello ",$a;
The result is as shown below:
$a='Bob';
echo "Hello ".$a;
The result is the same:
$a='Bob';
echo "Hello $a";
Still the same result:
This is the unique style of PHP.
Another feature is the array in PHP. PHP array. In my opinion, PHP's array is a combination of python's list and dictionary. For the data stored, it does not need to declare the type like the array of C. Both integers and strings can be mixed and stored in the same array to "coexist peacefully"; at the same time, it does not only support the use of traditional arrays compiled from 0. The serial number indexing method can be indexed using strings, which is very similar to Python's dictionary. All in all, it's a very strange thing, but it's very convenient if you think about it carefully.
$arr = array(0=>50, 'g'=>'ggg',1=>'www','h'=> >
As shown above, arr is an array with four elements, 0 The number is an integer 50; the next element is the string ggg, indexed by the character "g"; the third element is the string www of element 1; the fourth element is the string hhh, indexed by the character "h".
Next, use the array_push function to append a string element www
$arr = array(0=>50,'g'=> ;'ggg',1=>'www','h'=>'hhh'); array_push($arr,'www'); print_r($arr); As shown in the picture above, although the added element is the fifth element, but continues to sort using index 2. This is my feeling about the basic syntax of PHP