I have this code:
$tierHosts['host'] = isset($host['name']) ? $host['name'] : $host;
It's working fine in PHP 5.5, but in PHP 5.3 the condition returns true while $host
contains a string like pjba01
. It returns the first letter of $tierHosts['host']
, that is, p
.
What's so wrong with my code?
(is_array($host) && isset($host["name"]))
. Always check against the type you need if it's not clear which type you'll received. For more details on the behaviour you described see Rizier123s answer. – Killam