PHP使用in_array函數(shù)檢查數(shù)組中是否存在某個(gè)值_PHP教程
Jul 13, 2016 am 10:00 AMPHP使用in_array函數(shù)檢查數(shù)組中是否存在某個(gè)值
?這篇文章主要介紹了PHP使用in_array函數(shù)檢查數(shù)組中是否存在某個(gè)值,較為詳細(xì)的分析了in_array函數(shù)的功能、定義及相關(guān)的使用技巧與注意事項(xiàng),具有一定參考借鑒價(jià)值,需要的朋友可以參考下
?
本文實(shí)例講述了PHP使用in_array函數(shù)檢查數(shù)組中是否存在某個(gè)值的方法。分享給大家供大家參考。具體分析如下:
PHP使用in_array()函數(shù)檢查數(shù)組中是否存在某個(gè)值,如果存在則返回 TRUE ,否則返回 FALSE了,非常的好用,下面我深入來為各位介紹in_array() 函數(shù).
最近在用php寫一段代碼時(shí),要用到判斷某值是否在另外一組值中。而in_array 函數(shù)就是用來檢查數(shù)組中是否存在某個(gè)值 。直接通過概念理解比較模糊,可以通過具體例子了解其作用。
語(yǔ)法如下:
?
1 |
bool in_array( mixed needle, array array [, bool strict] ) |
參數(shù)說明:
參數(shù) | 說明 |
---|---|
needle | 需要在數(shù)組中搜索的值,如果是字符串,則區(qū)分大小寫 |
array | 需要檢索的數(shù)組 |
strict | 可選,如果設(shè)置為 TRUE ,則還會(huì)對(duì) needle 與 array 中的值類型進(jìn)行檢查 |
例1:
?
1 2 3 4 5 6 7 8 9 |
$os = array("Mac", "NT", "Irix", "Linux"); if (in_array("Irix", $os)) { echo "Got Irix"; } if (in_array("mac", $os)) { echo "Got mac"; } ?> |
以上代碼的執(zhí)行結(jié)果是:
Got Irix
第二個(gè)條件失敗,因?yàn)?in_array() 是區(qū)分大小寫的。
例2:
?
1 2 3 4 5 6 |
$europe = array("美國(guó)","英國(guó)","法國(guó)","德國(guó)","意大利","西班牙","丹麥"); if (in_array("美國(guó)",$europe)) { echo "True"; } ?> |
同上面一樣,執(zhí)行結(jié)果為True 。
例3:嚴(yán)格類型檢查例子
?
1 2 3 4 5 6 7 8 9 |
$a = array('1.10', 12.4, 1.13); if (in_array('12.4', $a, true)) { echo "'12.4' found with strict check "; } if (in_array(1.13, $a, true)) { echo "1.13 found with strict check "; } ?> |
其輸出結(jié)果是:
1.13 found with strict check
例4:數(shù)組中套用數(shù)組
?
1 2 3 4 5 6 7 8 9 10 11 12 |
$a = array(array('p', 'h'), array('p', 'r'), 'o'); if (in_array(array('p', 'h'), $a)) { echo "'ph' was found "; } if (in_array(array('f', 'i'), $a)) { echo "'fi' was found "; } if (in_array('o', $a)) { echo "'o' was found "; } ?> |
其輸出結(jié)果為:
'ph' was found
'o' was found
其具體用法如下:
?
1 |
bool in_array(mixed $needle,array $haystack [, bool $strict = FALSE ]) |
在 haystack 中搜索 needle,如果沒有設(shè)置 strict 則使用寬松的比較。
注:自php5.4以后。數(shù)組定義由array()換成了array[] 。
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ??











PHP?? ?? ?? ID? ?? ??? Session_id () ??? ???? ???? Session_Start ()? ???? ????? ??????. 1. ??? ????? ?? _start ()? ?????. 2. Session_id ()? ???? ?? ID? ?? ABC123DEF456GHI789? ??? ???? ?????. 3. ??? ?? ??? Session_Start ()? ??????, ???? ???? ?????? ?? ??? ?????? ??? ??????. 4. ?? ID? ??, ?? ?? ? ?? ?? ??? ??? ? ??? ?????? ???????. ??? ???? ????? ID? ????? ?? ? ??? ??????.

PHP ????? ?? ???? ????? Syntax substr (String $ String, int $ start,? int $ length = null) ? substr () ??? ??? ? ??? ??? ???? ??? ??? ?????. ???? ?? ?? ??? ??? ?? ? ?? MB_SUBSTR () ??? ???? ?? ??? ??????. ?? ???? ?? ???? ?? ????? ?? exploit () ?? strtr ()? ???? ?? ?? ??? ?? ??? ?? ??? ?? ??? ? ????.

UnitTestingInphPinvolvesVeverifying individualCodeUnitsInitsIntsormeStodStocatchBugSearlyLylyLearLiAberFactoring.1) setupphPunitviacomposer, createEatestDirectory, and ConfigeAuteAutoloadandPhpunit.xml.2) writeTestCases-oct-oct-asserterfat

PHP?? ?? ???? ??? exploit () ??? ???? ???? ??? ???? ????. ? ??? ??? ?? ??? ?? ???? ?? ???? ??? ??? ?????. ??? Exploit (???, ???, ??)??, ??? ???? ????? ???? ?? ?????, ??? ????? ?? ?? ?????? ??? ?? ?????. ?? ?? $ str = "Apple, Banana, Orange"; $ arr = Explode ( ",", $ str); ??? [ "Apple", "Bana???

JavaScript ??? ??? ?? ?? ? ?? ???? ????. ?? ???? ???, ??, ??, ?, ???? ?? ? ??? ?????. ?? ????? ?? ?? ? ? ??? ????? ?? ??? ??? ????. ??, ?? ? ??? ?? ?? ??? ??? ??? ???? ??? ??? ???? ??? ?? ??? ????. ?? ? ????? ??? ???? ? ??? ? ??? TypeofNull? ??? ?????? ??? ? ????. ? ? ?? ??? ???? ?????? ????? ???? ??? ???? ? ??? ? ? ????.

STD :: Chrono? ?? ?? ??, ?? ?? ??, ?? ?? ? ?? ?? ? ?? ?? ??? ???? C?? ???? ??? ?????. 1. std :: chrono :: system_clock :: now ()? ???? ?? ??? ?? ? ??? ?? ??? ???? ?? ? ? ??? ??? ??? ???? ?? ?? ? ????. 2. std :: Chrono :: steady_clock? ???? ?? ??? ???? ?? ??? ???? duration_cast? ?? ?? ?, ? ? ?? ??? ??????. 3. ?? (time_point) ? ?? (??)? ?? ??? ? ? ??? ?? ??? ? ?? epoch (epoch)???? ???????.

JavaScript?? ??? ?? ?? ???? ??? ??????. ?? ???? ??? ?? ?? ???? ()? ??? array.includes (valuetofind)???. ?? ??? ?? ???? ?? ??. indexof (20)! == -1? ?? indexof ()? ??????. ?? ?? ??? ???? ?? user.some (user => user.id === 1)? ?? ?? ??? ?? () ???? ???????.

PHP?? ?? ??? ?? ???? ????? ?? ??? ???? ???? ??? $ _session ? ??? ???? ????. 1. ? ???? ?? ??? ???? ?? Session_Start ()? ???? ???? ??? ???????. 2. $ _session [ 'username'] = 'johndoe'? ?? ?? ??? ?????. 3. ?? ????? session_start ()? ?? ? ? ??? ? ??? ?? ??? ???????. 4. Session_Start ()? ? ????? ???? ??? ????, ???? ?? ???? ??, ??? ?? ???? ??? ?? ? ? ??? ??????. 5. SES? ??????
