Learn PHP record "six"

Source: Internet
Author: User
Tags learn php

1. Expression

The expression is the most basic one.

$fist $second $third

True calculates second,false calculation third. Speak the truth.

There is a strict equality operator, very good. = = = The comparison value and type are the same.

In the principle of expression, the self-increment here is a bit different.

The pre-increment + + $a means to read $ A before incrementing, so call before increment. Then since the increase is read and then self-increase, interpretation is excellent, very clear.

2. Operators

Looked at, in fact, are used.  such as the string. is to connect two strings

3. Control statements

<? PHP      if (expr)         statement?>
<? PHP     if ($a$b) {        echo "a > B";    } ElseIf ($a$b) {        echo "a = B";    } Else {        echo "Else";    }

Another is the use of a colon instead of curly braces, but the end of the endif end, and ENDfor Endforeach and so on a bunch of

foreach is very important, because the official explanation for this is that: theforeach syntax structure provides a simple way to iterate through an array

It is born and is traversed by an array.

The previously mentioned modification of value in foreach, which introduces the way to dereference

Unset ($value); Cancels the reference.

This is because: the $value reference to the last element of theWarning array remains after the foreach loop. It is recommended to use unset () to destroy it.

Officials have introduced 10,000 ways to say they're like foreach! I don't even know list and each!. Doing

------------------------------------------list ()----------------------------------------------------------

The list is very clear, just take the values out of the array and pay the variables one by one.

List ($drink, $brown, $tarf) = Array (' test1 ', ' test2 ', ' test3 ');

So the result is $drink = ' test1 ' and so on~

Another feature is the processing of nested arrays, which is also excellent.

    

$arr Array (                 [' E ', ' d '],                            [' A, ' Z '],        ); foreach ($arr as List ($e, $a)) {    echo "$e,,,, $a \ n";}

-----------------------------------------End list ()------------------------------------------------------

-------------------------------------each ()--------------------------------------

    Array each of &$array These is the original, you can see that there are references in the inside, so each action is to modify the old array!

It returns the current key/value of the array, and then once called, the pointer points to the next key/value. If you want to reset the position of the pointer, you want to restore the

Call Reset ();

Of course, if the key value is not the case, the default is 0,1,2-----。 But the array here would have been 0,1,2 by default----

Well.

-------------------------------------end each ()----------------------------------

So there's a way to iterate through the array with list and each.

 <? php   $arr  = array   ( ' test ' = ' test value ', ' test2 ' = ' Test value2 ',     ); reset  ( $arr ); // reset before using each  while  (list  ( $key ,  $value ) = each  ( $arr   echo "  $key  => $value  \ n " 

Finally understand, this place is very confused before. In fact, each time each takes out both the current key and value, and the pointer points to the next key/value.

Let's get ready for bed tomorrow.

Learn PHP record "six"

Related Article

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.