Int type?

Source: Internet
Author: User
Int type?
 111,2=>22111,3=>3333);     $y1=in_array(111,$x1);     echo $y1;     echo "\r\n";          $x2=array(1=>111,2=>2211,3=>3333);     $y2=in_array('111',$x2);     echo $y2;     echo "\r\n";          $x3=array(1=>111,2=>2211,3=>3333);     $y3=in_array("111",$x3);     echo $y3;     echo "\r\n";    ?>


Problem:
In the above PHP program, the 1st parameters of the function are: int type, which can be expressed in the following three ways:
(1) 111
2) '123'
3) "111"

That's all right. why?


Reply to discussion (solution)

Because you have not specified the third parameter for in_array, you can only compare whether the values are equal. The values of 111, '123', and "111" are equal.

First 2) and 3) no difference
Next, you need to check the manual. in_array has a third parameter. If this parameter is not used, the default value is false.
Would you like to add the third parameter true?

Because you have not specified the third parameter for in_array, you can only compare whether the values are equal. The values of 111, '123', and "111" are equal.

You do not need to consider the first 3rd parameters.
PHP syntax, int type, can be expressed in these three ways?

No
111 indicates int
'123', "111" indicates a string

No
111 indicates int
'123', "111" indicates a string

Why is the program correct?

I have already said this on the first floor. I suggest you go to the manual.
Http://php.net/manual/zh/function.in-array.php

 "A", 2 => "B", 3 => "c"); $ y1 = in_array (a, $ x1); // This line has a syntax error! // PHP Notice: Use of undefined constant a-assumed 'A' in/var/www/B. php on line 4 echo $ y1; echo "\ r \ n"; $ x2 = array (1 => "a", 2 => "B ", 3 => "c"); $ y2 = in_array ('A', $ x2); echo $ y2; echo "\ r \ n "; $ x3 = array (1 => "a", 2 => "B", 3 => "c"); $ y3 = in_array ("a", $ x3 ); echo $ y3; echo "\ r \ n" ;?>


The in_array () function. The first parameter is the struct type. The following three representations:
1) a // PHP syntax error.
2) 'A'
3) ""

You have already asked about this post. check it out.

I have already said this on the first floor. I suggest you go to the manual.
Http://php.net/manual/zh/function.in-array.php

bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )


The in_array () function has 1st parameters. its type is mixed.
That is: its type is unknown, but it is one of the PHP types!

Int integer:
(1) 111
2) '123'
3) "111"
In this way, there are no compilation errors!
That is to say, they are all int integers?


Because you have not specified the third parameter for in_array, you can only compare whether the values are equal. The values of 111, '123', and "111" are equal.

You do not need to consider the first 3rd parameters.
PHP syntax, int type, can be expressed in these three ways?
Php is a weak language and automatically changes the data type according to the context.
For example
Echo '000000' + 2; // output 111
Echo 111. 2; // output 1112

For #8, when the force type check is canceled
Error_reporting (E_ALL ^ E_NOTICE );
$ X1 = array (1 => "a", 2 => "B", 3 => "c ");
$ Y1 = in_array (a, $ x1 );
No error is reported!

You have already asked about this post. check it out.

This post asks about the PHP type.

It has nothing to do with the in_array () 3rd parameter!



Because you have not specified the third parameter for in_array, you can only compare whether the values are equal. The values of 111, '123', and "111" are equal.

You do not need to consider the first 3rd parameters.
PHP syntax, int type, can be expressed in these three ways?
Php is a weak language and automatically changes the data type according to the context.
For example
Echo '000000' + 2; // output 111
Echo 111. 2; // output 1112

For #8, when the force type check is canceled
Error_reporting (E_ALL ^ E_NOTICE );
$ X1 = array (1 => "a", 2 => "B", 3 => "c ");
$ Y1 = in_array (a, $ x1 );
No error is reported!

PHP is a weak language.
I don't know how weak it is. how many possibilities are there?
For example, an int type can be written in three ways.


Unlike the C language, 1 is 1, 2 is 2, and the types are strictly normalized!

Weak is relatively strong
C language is a strongly typed language

All scripting languages are weak because they do not need a compilation process. No need to pre-allocate storage space

I feel like LZ is killed and I don't want to read the manual, so I'll just copy it.
-----------------------------
Bool in_array (mixed $ needle, array $ haystack [, bool $ strict = FALSE])
Search for needle in haystack. if strict is not set, use loose comparison.
......
Strict
If the value of the third strict parameter is TRUE, the in_array () function checks whether the needle type is the same as that in haystack.
-------------------------------
I hope I don't want to watch this building either.

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.