Logo

Programming-Idioms

History of Idiom 52 > diff from v29 to v30

Edit summary for version 30 by ancarda:
[PHP] Added demo, documentation URL, and defaulted to the 3rd parameter

Version 29

2019-09-27, 09:54:31

Version 30

2019-09-27, 09:57:27

Idiom #52 Check if map contains value

Determine whether map m contains an entry with value v, for some key.

Illustration

Idiom #52 Check if map contains value

Determine whether map m contains an entry with value v, for some key.

Illustration
Extra Keywords
table dictionary hash
Extra Keywords
table dictionary hash
Code
in_array($v, $m);
Code
in_array($v, $m, true);
Comments bubble
arrays in PHP are maps
Comments bubble
arrays in PHP are maps.

Set the 3rd parameter to false if you want a type-insensitive check.
Doc URL
https://www.php.net/in_array
Demo URL
https://3v4l.org/0KhIp