Description
array_search(): Searches the array for a given value and returns the corresponding key if successful
Équivalent à la function [PHP array_search
Source Code
Code: bash
Parameters
needleis the searched valuehaystackis the array where to search
Return Values
- Returns the key for
needle, if is found into the arrayhaystack - Otherwise, returns
1: considere this value asFALSE.
Example
declare -a color=("blue", "red", "green", "grey");
echo "$(array_search "red" "${color[@]}")"