<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%23s\n", "Name", "Price"); printf("%'-43s\n", ""); foreach ( $products as $key=>$val ) printf( "%-20s%20.2f\n", $key, $val ); printf("</pre>"); ?> </body> </html>