Browse - Programming Tips - php: check for missing value in associative array

Date: 2018nov9
Language: php

Q.  php: check for missing value in associative array

A.  If you expect that the lookup will succeed most of the time you can use @ in from of the array
and check for null.

$n = @$totals[$name]; if ($n === null) $n = 0; print "Name $name is used $n times\n";
You can also use isset(), in_array(), array_search(), array_key_exists()