function

array_search . array . sncode

VERSION5.95 Searches a value in the array

ARRAY_SEARCH

NAME

array_search : Searches the array for a given value and returns the first corresponding key if successful

SYNOPSIS

array_search(array, needle);

DESCRIPTION

This function searches in the array and try to find a desired value and it returns its corresponding index key.

Form 1:

a = ["t","a",1];

a.array_search("a");

Form 2:

a = ["t","a",1];

array_search(a, 1);

 

RETURN

This function returns the array index key starting from 0 if found;otherwise, it returns -1.

EXAMPLES

a = [1, 2, “3”];
a.array_search(1);//return 0
a.array_search(2);//return 1
a.array_search(3);//return -1
a.array_search(4);//return -1
b = [];
b.array_search(1);//return -1

 

AUTHOR

Written by Pierre Laplante, <laplante@sednove.com>

VERSION

Available from version 5.95