| echo Statement | HTML Source Code | Web Page Display |
|---|---|---|
| echo "Hello World!"; | Hello World! | Hello World! |
| echo "Hello World!"; echo "Here I am!"; |
Hello World! Here I am! |
Hello World!Here I am! |
| echo "Hello World!\n"; echo "Here I am!"; |
Hello World! Here I am! |
Hello World!Here I am! |
| echo "Hello World!"; echo "<br>"; echo "Here I am!"; |
Hello World!<br> Here I am! |
Hello World! Here I am! |
| echo "Hello"; echo " World!<br>\n"; echo "Here I am!"; |
Hello World!<br> Here I am! |
Hello World! Here I am! |
| PHP Statements | Description |
|---|---|
| $counter+=2; | add 2 to the counter |
| $counter-=3; | subtract 3 from the counter |
| $counter*=2; | multiply the counter by 2 |
| $counter/=3; | divide counter by 3 |
| Sort Statement | What It Does |
|---|---|
| sort($arrayname) | Sorts by value, assigns new numbers as keys |
| asort($arrayname) | Sorts by value, keeps the same key |
| rsort($arrayname) | Sorts by value in reverse order, assigns new numbers as keys |
| arsort($arrayname) | Sorts by value in reverse order, keeps the same key |
| ksort($arrayname) | Sorts by key |
| krsort($arrayname) | Sorts by key in reverse order |
| usort($arrayname, functionname) | Sorts by a function (see Using Functions, later in this chapter |
| PHP Commands | Description |
|---|---|
| current($arrayname) | refers to the value currently under the pointer, does not move the pointer |
| next($arrayname) | moves the pointer to the value after the current value |
| prev($arrayname) | moves the pointer to the value before the current pointer location |
| end($arrayname) | moves the pointer to the last value in the array |
| reset($arrayname) | moves the pointer to the first value in the array |
foreach( $arrayname as $keyname => $valuename
{
block of statements;
}| $productPrices |
key |
value |
|
| key | value | ||
| clothing | shirt | 20.00 | |
| pants | 22.50 | ||
| linens | blanket | 25.00 | |
| bedspread | 50.00 | ||
| furniture | lamp | 44.00 | |
| rug | 75.00 | ||
| shirt: | $20.00 |
| pants: | $22.50 |
| blanket: | $25.00 |
| bedspread: | $50.00 |
| lamp: | $44.00 |
| rug: | $75.00 |