๐ฏ By the end of this lesson you canโฆ
- Choose single or double quotes
- Join strings with . and .=
- Format output with printf and number_format
๐ PHP
quotes.php
๐ Tap a line to explain it
1<?php2$name = "Kabir";3echo "Hi $name\n";4echo 'Hi $name\n', "\n";5echo "Hi {$name}!\n";6$msg = "Good";7$msg .= " morning";8echo $msg . ", " . $name . "\n";
๐ PHP
formatting.php
๐ Tap a line to explain it
1<?php2$name = "Kabir";3$price = 1234.5;4printf("Price: โน%.2f\n", $price);5printf("%-8s|%5d\n", "Pens", 12);6echo number_format(1234567.891, 2), "\n";7echo <<<TEXT8Dear $name,9 Your order is ready.10TEXT;
๐ฎ What will this display?
What does this print?
1<?php2$x = 5;3echo 'x is $x';
๐ ๏ธ Receipt line
Read an item and a price. Print <item>: โน<price with 2 decimals>, e.g. Notebook: โน45.00.
๐ Key takeaways
- Double quotes replace variables (
"Hi $name"); single quotes donโt ('Hi $name'). .joins;.=appends.printf("%.2f", $x)andnumber_format($x, 2)format numbers.
Finished reading & practising?
Saved in this browser. Create a free account to keep it forever.