Using printf() to Format a List of Product Prices
<html>
<head>
<title>Using printf() to Format a List of Product Prices</title>
</head>
<body>
<?php
$products = array (
"A"=>2.4,
"B"=>4,
"C"=>80.6
);
print "<pre>";
printf ("%-20s%23s\n", "Name", "Price");
printf ("%'-43s\n", "");
foreach ( $products as $Key=>$val ) {
printf ("%-20s%20.2f\n", $Key, $val);
}
print "</pre>";
?>
</body>
</html>
Related examples in the same category