Using printf() to Format a List of Product Prices : Printf : Development PHP Source Code


PHP Source Code » Development » Printf »

 

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("Pencil"=>"222.4",
                  "Cake"=>"4",
                  "Coffee table"=>80.6
);
print "<pre>";
printf("%-20s%23sn""Name""Price");
printf("%'-43sn""");
foreach $products as $key=>$val )
    printf"%-20s%20.2fn", $key, $val );
printf("</pre>");
?>
 </body>
</html>

           
       



HTML code for linking to this page:

Follow Navioo On Twitter

PHP Source Code

 Navioo Development
» Printf