How can the floor function in PHP be used to truncate decimal numbers?

To truncate decimal numbers in PHP, you can use the floor() function which returns the largest integer less than or equal to a given number. This function effectively removes the decimal part of a number, truncating it towards negative infinity.

$number = 3.14;
$truncated_number = floor($number);
echo $truncated_number; // Output: 3