PHP Hours to Float Conversion in PHP
Convert hours in string format to numerical value in PHP using the hoursToFloat function. Easily convert time values like 1:30 to 1.5.
```php
function hoursToFloat($hours) {
$minutes = 0;
if (strpos($hours, ':') !== false) {
$exploded = explode(':', $hours);
$hours = $exploded[0];
$minutes = $exploded[1];
}
return floatval($hours) + ($minutes / 60);
}
echo hoursToFloat('38:55');
echo hoursToFloat('47:01');
```