Development Php



Using printf() to format a list of product prices


$products = Array("Pencil"=>"222.4",
                  "Cake"=>"4",
                  "Coffee table"=>80.6
);
print "
";
printf("%-20s%23s\n", "Name", "Price");
printf("%'-43s\n", "");
foreach ( $products as $key=>$val )
    printf( "%-20s%20.2f\n", $key, $val );
printf("
");
?>