<? $x1=array(1=>111,2=>12,3=>3333); $y1=in_array(12,$x1,true); echo $y1; echo "\r\n"; $x2=array(1=>111,2=>12,3=>3333); $y2=in_array('12',$x2,true); echo $y2; echo "\r\n"; $x3=array(1=>111,2=>12,3=>3333); $y3=in_array("12",$x3,true); echo $y3; echo "\r\n"; ?>
程序输出:
1
0
0
问题:
1.上面程序编译,没语法错误。
函数in_array( ),第1个参数,都是int整型。
函数in_array( ),第3个参数:true,有什么作用?
为什么,第1个数组,返回结果:1,找到。
每2,3个数组,返回结果:0,找不到?
回复讨论(解决方案)
bool in_array ( mixed needle, array haystack [, bool strict] )
在 haystack 中搜索 needle,如果找到则返回 TRUE,否则返回 FALSE。
如果第三个参数 strict 的值为 TRUE 则 in_array() 函数还会检查 needle 的类型是否和 haystack 中的相同。
bool in_array ( mixed needle, array haystack [, bool strict] )
在 haystack 中搜索 needle,如果找到则返回 TRUE,否则返回 FALSE。
如果第三个参数 strict 的值为 TRUE 则 in_array() 函数还会检查 needle 的类型是否和 haystack 中的相同。
1)12与12,内容相同,类型也相同。返回:1
2)'12'与12,内容相同,类型为什么不同?
3)"12"与12,内容相同,类型为什么不同?
函数in_array( ),执行过程是否这样:
1.检查函数各个参数的类型。
如果,类型不对,显示语法错误。
如果,类型对,执行2
2.查找数组。
3.如果,找到,返回结果:1
如果,找不到,返回结果:0
楼主,12是数字,'12'和"12"是字符串,所以类型不同
函数参数:true,PHP官方中文文档,不是很详细。
我的理解是:
函数in_array( )
1)没true,第1个参数,使用类型转换后的值,与数组元素比较。进行查找。
2)没true,第1个参数,使用类型转换前的值,与数组元素比较。进行查找。
对否?
更改:
函数参数:true,PHP官方中文文档,不是很详细。
我的理解是:
函数in_array( )
1)没true,第1个参数,使用类型转换后的值,与数组元素比较。进行查找。
2)加true,第1个参数,使用类型转换前的值,与数组元素比较。进行查找。
对否?
<? $x1=array(1=>"aaaa",2=>12,3=>"bb"); $y1=in_array(12,$x1); //类型转换后值:12 echo $y1; echo "\r\n"; $x2=array(1=>111,2=>12,3=>3333); $y2=in_array('12',$x2); //类型转换后值:12 echo $y2; echo "\r\n"; $x3=array(1=>111,2=>12,3=>3333); $y3=in_array("12",$x3); //类型转换后值:12 echo $y3; echo "\r\n"; echo "------------------------------"; ?><? $x1=array(1=>"aaaa",2=>12,3=>"bb"); $y1=in_array(12,$x1,true); //类型转换前值:12 echo $y1; echo "\r\n"; $x2=array(1=>111,2=>12,3=>3333); $y2=in_array('12',$x2,true); //类型转换前值:'12' ,是个字符串。 echo $y2; echo "\r\n"; $x3=array(1=>111,2=>12,3=>3333); $y3=in_array("12",$x3,true); //类型转换前值:"12",是个字符串。 echo $y3; echo "\r\n"; ?>
程序输出:
1
1
1
---------------------------
1
0
0
bool in_array ( mixed needle, array haystack [, bool strict] )
在 haystack 中搜索 needle,如果找到则返回 TRUE,否则返回 FALSE。
如果第三个参数 strict 的值为 TRUE 则 in_array() 函数还会检查 needle 的类型是否和 haystack 中的相同。
+1
bool in_array ( mixed needle, array haystack [, bool strict] )
在 haystack 中搜索 needle,如果找到则返回 TRUE,否则返回 FALSE。
如果第三个参数 strict 的值为 TRUE 则 in_array() 函数还会检查 needle 的类型是否和 haystack 中的相同。
6楼,对否?

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software