当前位置:网站首页>PHP in_ Array() function

PHP in_ Array() function

2022-06-24 05:11:00 User 1448800

example

Search for values in an array "Glenn" , And output some text :

<?php
$people = array("Bill", "Steve", "Mark", "David");

if (in_array("Mark", $people))
  {
  echo " Match found ";
  }
else
  {
  echo " Match not found ";
  }
?>

Definition and Usage

in_array() The function searches the array for the specified value .

notes : If search The parameter is a string and type Parameter is set to TRUE, The search is case sensitive .

grammar

in_array(search,array,type)

Parameters

describe

search

It's necessary . Specify the value to search in the array .

array

It's necessary . Specify the array to search .

type

Optional . If this parameter is set to true, Then check whether the data searched is of the same type as the value of the array .

explain

If the given value search Exists in arrays array Middle returns true. If the third parameter is set to true, The function returns... Only if the element exists in the array and the data type is the same as the given value true.

If no parameters are found in the array , The function returns false.

notes : If search The argument is a string , And type Parameter set to true, The search is case sensitive .

Technical details

Return value :

Returns... If a value is found in the array TRUE, Otherwise return to FALSE.

PHP edition :

4+

Changelog:

since PHP 4.2 rise ,search  Parameters can now also be arrays .

More instances

Example 1

Use all parameters :

<?php
$people = array("Bill", "Steve", "Mark", "David");

if (in_array("23", $people, TRUE))
  {
  echo " Match found <br>";
  }
else
  {
  echo " Match not found <br>";
  }
if (in_array("Mark",$people, TRUE))
  {
  echo " Match found <br>";
  }
else
  {
  echo " Match not found <br>";
  }

if (in_array(23,$people, TRUE))
  {
  echo " Match found <br>";
  }
else
  {
  echo " Match not found <br>";
  }
?>
原网站

版权声明
本文为[User 1448800]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/08/20210821105037119k.html