先看下PHP實(shí)例:
- $array = explode(',','1101,1102,1103,418,617,712,713,312,313,104,105,106,107,108');
- if( in_array('8',$array) )
- {
- echo 'a';
- }
- else
- {
- echo 'b';
- }
定義和用法:in_array() 函數(shù)在數(shù)組中搜索給定的值.
語法:in_array(value,array,type)參數(shù) 描述
value 必需,規(guī)定要在數(shù)組搜索的值.
array 必需,規(guī)定要搜索的數(shù)組.
type 可選,如果設(shè)置該參數(shù)為 true,則檢查搜索的數(shù)據(jù)與數(shù)組的值的類型是否相同.
說明:如果給定的值 value 存在于數(shù)組 array 中則返回 true,如果第三個(gè)參數(shù)設(shè)置為 true,函數(shù)只有在元素存在于數(shù)組中且數(shù)據(jù)類型與給定值相同時(shí)才返回 true.
如果沒有在數(shù)組中找到參數(shù),函數(shù)返回 false。
注釋:如果 value 參數(shù)是字符串,且 type 參數(shù)設(shè)置為 true,則搜索區(qū)分大小寫.
新聞熱點(diǎn)
疑難解答