/*
Common format specifiers
-----------------------------------
%-10s // Left-aligned string, width 10
%10s // Right-aligned string, width 10
%5d // Integer, width 5
%08d // Integer, width 8, padded with zeros
%12.2f // Float, width 12, 2 decimal places
*/
/**
* Formats a record using fixed-width fields.
*
* %-15s = left-aligned string, width 15
* %10d = right-aligned integer, width 10
* %12.2f = right-aligned floating-point number,
* width 12, 2 decimal places
*/
function formatRecord(string $name, int $age, float $salary): string
{
return sprintf(
"%-15s%10d%12.2f",
$name,
$age,
$salary
);
}
// Store the formatted string in a variable
$result = formatRecord("Freya", 37, 98000.00);
echo $result . PHP_EOL;
/*
run:
Freya 37 98000.00
*/