Home  >  Article  >  Backend Development  >  First introduction to PHP (1) basic syntax, first introduction to basic syntax of PHP_PHP tutorial

First introduction to PHP (1) basic syntax, first introduction to basic syntax of PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:54:52708browse

First introduction to the basic syntax of PHP (1), first introduction to the basic syntax of PHP

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:

First introduction to PHP (1) basic syntax, first introduction to basic syntax of PHP_PHP tutorial$a='Bob';
 echo "Hello ".$a;

The result is the same:

First introduction to PHP (1) basic syntax, first introduction to basic syntax of PHP_PHP tutorial$a='Bob';
 echo "Hello $a";

Still the same result:

First introduction to PHP (1) basic syntax, first introduction to basic syntax of PHP_PHP tutorial 

 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'=> >

 First introduction to PHP (1) basic syntax, first introduction to basic syntax of PHP_PHP tutorialAs 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);

 First introduction to PHP (1) basic syntax, first introduction to basic syntax of PHP_PHP tutorial 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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1117675.htmlTechArticleFirst introduction to PHP (1) basic syntax, first introduction to php basic syntax. I have been preparing to learn PHP, but the result was that some time ago Something happened and it delayed me for a while. Now hurry up and catch up! This series just talks about...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn