How do you check if a variable has numeric content?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Amit Tiwari
Forum Newbie
Posts: 9
Joined: Tue Feb 07, 2017 5:46 am

Re: How do you check if a variable has numeric content?

Post by Amit Tiwari »

function ping($host, $count = 3, $port = 60, $timeout = 8) {
$ping_times = [];

for ($i = 0; $i < $count; $i++) {
$start_time = microtime(true);
$fp = fsockopen($host, $port, $errno, $errstr, $timeout);

if (!$fp) {
echo "sorry this is not right";
}

$end_time = microtime(true);
fclose($fp);
$response_time = round((($end_time - $start_time) * 1000), 0);
$ping_times[] = $response_time;
}

return $ping_times;
}

if (isset($domain))
{
$ping = ping("www.otssolutions.com", 80, 10);
$average = array_sum($ping_times) / count($pings);
}


echo "$average";
Post Reply