I am a newbie to ask a question about the if statement in a function.

Source: Internet
Author: User
Ask a question about the if statement in a function. if a Cainiao has similar functions, it is incomplete. just give an example.

Function p_abc ($ a = '', $ B ='', $ c = ''){
$ A = xxx
If ($ B = '000000 '){
$ A = xxx + 1
}
$ C = yyy

}


When $ B = '000000', the function can run normally. when $ B is not equal to 255, it seems that $ c = yyy cannot be executed (I'm not sure ). Cause program errors.

Why? I am a newbie, please tell me.




Reply to discussion (solution)

One = is a value assignment.
Two = is a comparison

Your if ($ B = '000000') {is to make $ B 255, and the expression will always be true.
Should Write if ($ B = '000000 '){

If ($ B = '000000 ')

There is no problem with your delivery syntax, but this must be true. this is a value assignment.

Use = and = for equality in php
Example name result
$ A = $ B is equal to TRUE. if $ a is equal to $ B after type conversion.
$ A ===$ B all equal to TRUE, if $ a is equal to $ B, and their types are the same.
$! = $ B is not equal to TRUE. if $ a is not equal to $ B after type conversion.
$ A <> $ B is not equal to TRUE. if $ a is not equal to $ B after type conversion.
$! = $ B is not all TRUE, if $ a is not equal to $ B, or they are of different types.
$ A <$ B small and TRUE, if $ a is strictly less than $ B.
$ A> $ B is greater than TRUE if $ a is strictly greater than $ B.
$ A <= $ B is less than or equal to TRUE, if $ a is less than or equal to $ B.
$ A >=$ B is greater than or equal to TRUE if $ a is greater than or equal to $ B.

Reference: http://www.php.net/manual/zh/language.operators.comparison.php

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.