According to the manual:
Returns the host name on success, the unmodified ip_address on failure, or FALSE on malformed input.
So you could do this:
<?php
$ips = array("xxx.xxx.xxx.4","xxx.xxx.xxx.5");
foreach ($ips as $value) {
$hostname = gethostbyaddr($value);
if ($hostname === false) { //malformed input
echo 'IP "' . $value . '" was malformed<br />';
} else if ($hostname === $value) { //failure
echo 'Hostname could not be found for "' . $value . '"<br />';
} else { //success
echo 'Hostname: ' . $hostname . '<br />';
}
}
?>