Get the App
SLTechnology News&Howtos  ›  Development  › 

How does php determine whether the value is in a two-dimensional array

Shulou Source: shulou.com Published: 2022-05-31 17:20:06 09月27日 Update

This article mainly introduces php how to judge whether the value is in the two-dimensional array of related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you read this php how to determine whether the value in the two-dimensional array article will have a harvest, let's take a look.

Judgment method: 1, loop through the two-dimensional array, syntax "foreach ($arr as $v) {}", will assign the current subarray to "$v"; 2, in the loop body, use in_array () to determine whether the specified value is in the subarray, syntax "in_array (" value ", $v)", and return TRUE if it is.

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

How does php determine whether the value is in a two-dimensional array?

In php, you can use the foreach statement and the in_array function to determine whether the value is in a two-dimensional array.

1. Use the foreach statement to loop through a two-dimensional array

Iterate through the given two-dimensional array, assigning a subarray of the current array to $v in each loop.

2. In the body of the loop, use in_array () to determine whether the specified value is in the subarray.

In_array (search,array) searches the array for the existence of the specified value, and returns TRUE if the value is found in the array, FALSE otherwise.

Foreach ($arr as $v) {if (in_array ("bb", $v)) {echo "specified value in two-dimensional array";}}

This is the end of the article on "how php determines whether the value is in a two-dimensional array". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to judge whether the value is in a two-dimensional array". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Array two-dimensional loop knowledge content loop body article sentence grammar lieutenant general value function simple operation tutorial method easy to understand more environment computer look Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Microsoft MariaDB Docker Shulou Tech Info