Get the App
SLTechnology News&Howtos  ›  Development  › 

How php queries whether it contains specified array values

Shulou Source: shulou.com Published: 2022-06-01 17:45:52 10月16日 Update

This article is about how PHP queries whether or not an array contains a specified value. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

Query methods: 1. Use the in_array() function, syntax "in_array(value,array)", return TRUE if it contains;2. Use the array_search() function, syntax "array_search(value,array)", return the corresponding key name if it contains.

Operating environment of this tutorial: Windows 7 system, PHP7.1 version, DELL G3 computer

php queries whether the specified array contains values

Method 1: Use the in_array() function

The in_array() function searches for the presence of the specified value in an array. Returns TRUE if a value is found in the array, FALSE otherwise.

Method 2: Use the array_search() function

The array_search() function searches an array for a key and returns the corresponding key name.

Returns the key name if the specified key is found in the array; otherwise returns FALSE. If a key is found more than once in the array, the key name matched by the first key found is returned.

Thank you for reading! About "php how to query whether it contains specified array values" This article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Tags: Array function query method content more article grammar search good practical tutorial article environment computer see knowledge first time system reference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Information NVidia MySQL OPPO Reno