先給大家介紹php in array函數(shù)基本知識(shí)熱熱身。
定義和用法
in_array() 函數(shù)在數(shù)組中搜索給定的值。
語(yǔ)法
in_array(value,array,type)
| 參數(shù) | 描述 |
|---|---|
| value | 必需。規(guī)定要在數(shù)組搜索的值。 |
| array | 必需。規(guī)定要搜索的數(shù)組。 |
| type | 可選。如果設(shè)置該參數(shù)為 true,則檢查搜索的數(shù)據(jù)與數(shù)組的值的類(lèi)型是否相同。 |
說(shuō)明
如果給定的值 value 存在于數(shù)組 array 中則返回 true。如果第三個(gè)參數(shù)設(shè)置為 true,函數(shù)只有在元素存在于數(shù)組中且數(shù)據(jù)類(lèi)型與給定值相同時(shí)才返回 true。
如果沒(méi)有在數(shù)組中找到參數(shù),函數(shù)返回 false。
注釋?zhuān)喝绻?value 參數(shù)是字符串,且 type 參數(shù)設(shè)置為 true,則搜索區(qū)分大小寫(xiě)。
無(wú)意中看到一段代碼
- <?php
- $y="1800";
- $x = array();
- for($j=0;$j<50000;$j++){
- $x[]= "{$j}";
- }
- for($i=0;$i<30000;$i++){
- if(in_array($y,$x)){
- continue;
- }
- }
新聞熱點(diǎn)
疑難解答