PHP

PHP Menu

PHP

array_search() Function - Definition, Syntax, Parameters, Examples

Definition

The array_search() function search an array for a value and returns the key.

Syntax

array_search(value, array, strict)

Parameters

Parameter Description
value Required. Specifies the value to search for.
array Required. Specifies the array to search in.
strict Optional. If this parameter is set to true, then this function will search for identical elements in the array. Possible values: true; false - Default

Example

<?php
// Example 1 $ages = array("Mark" => 22, "Jeff" => 32, "Mike" => 28); echo array_search(28, $ages); echo "<br>";
// Example 2 $ages2 = array("Mark" => 22, "Jeff" => "22", "Mike" => 28); echo array_search("22", $ages2); echo "<br>";

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods