How to find the specified value in an array using the array_search function in php

墨辰丷
Release: 2023-03-31 18:52:01
Original
2788 people have browsed it

This article mainly introduces the method of php to find the specified value in the array. The example analyzes the usage skills of the array_search function in php to find the specified value of the array. It has certain reference value. Friends who need it can refer to it

The example in this article describes how PHP searches for a specified value in an array. The details are as follows:

There are two functions in php that can determine whether the array contains the specified value, namely: array_search($value, $array) and in_array($value, $array), array_search can find out The position where the specified value appears in the array. The in_array function only determines whether the specified value exists in the array and returns a bool value

<?php 
$array = array("Perl", "PHP", "Java", "PHP");
print("Search 1: ".array_search("PHP",$array)."\n");
print("Search 2: ".array_search("Perl",$array)."\n");
print("Search 3: ".array_search("C#",$array)."\n");
print("\n");
?>
Copy after login

The output results are as follows

Search 1: 1
Search 2: 0
Search 3:
Copy after login

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

The definition and use of magic methods in PHP

##A brief introduction to the adapter pattern in PHP design patterns

A brief introduction to the decorator pattern in PHP design patterns

The above is the detailed content of How to find the specified value in an array using the array_search function in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template