I have been preparing to learn PHP, but something happened some time ago and I was delayed 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 directly called by writing its name in 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 splicing in PHP can be done like Python using ",", For example:
$a='Bob';
echo "Hello ",$a;
The result is as shown below:
But The more orthodox way of writing PHP is to use "." for splicing, such as:
$a='Bob';
echo "Hello ".$a;
The result is the same:
Here comes the most amazing thing, PHP has an HTML-style usage, which is to directly quote variables in the string:
$a='Bob' ;
echo "Hello $a";
Still the same result:
This It 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 C arrays. 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'=>'hhh');
As shown above, arr is an array with four elements, number 0 is the integer 50; the next element is the string ggg, using the character " g" index; the third element is the string www of element No. 1; the fourth element is the string hhh, indexed using the character "h". Next, use the array_push function to append a character to the end of the array String element www $arr = array(0 =>50,'g'=>'ggg',1=> array_push($arr,'www'); As shown in the picture above, although the added element is the fifth element, it still continues to be sorted and used. Index No. 2. This is my feeling about the basic syntax of PHP
The above introduces the basic syntax of PHP, including PHP and syntax. I hope it will be helpful to friends who are interested in PHP tutorials.
print_r($arr);