String Variables in PHP
String variables are used for values that contain characters.
In this chapter we are going to look at the most common functions and operators used to manipulate strings in PHP.
After we create a string we can manipulate it. A string can be used directly in a function or it can be stored in a variable.
Below, the PHP script assigns the text "Hello World" to a string variable called $*txt:
Results:
Hello World |
The Concatenation Operator
There is only one string operator in PHP.
The concatenation operator (.) is used to put two string values together.
To concatenate two string variables together, use the concatenation operator:
Results:
Hello World! What a nice day! |
The if Statement
Use the if statement to execute some code only if a specified condition is true.
The if...else Statementt
Use the if....else statement to execute some code if a condition is true and another code if a condition is false.
The if...elseif....else Statement
Use the if....elseif...else statement to select one of several blocks of code to be executed.
The PHP Switch Statement
Use the switch statement to select one of many blocks of code to be executed.
Multidimensional Arrays
In a multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array, and so on.
Results:
Array ( [Griffin] => Array ( [0] => Peter [1] => Lois [2] => Megan ) [Quagmire] => Array ( [0] => Glenn ) [Brown] => Array ( [0] => Cleveland [1] => Loretta [2] => Junior ) ) |
The for Loop
The for loop is used when you know in advance how many times the script should run.
The $_GET Function
The built-in $_GET function is used to collect values from a form sent with method="get".
Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send.
The $_POST Function
The built-in $_POST function is used to collect values from a form sent with method="post".
Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.
No comments:
Post a Comment