The print statement is used to display the array keys and element values. In this example, an array is created along with a foreach loop. See online demo and code Print statement with arrays This is the print statement with variables: See online demo and code The print statement with variables In the following example, three simple strings are displayed by using the print statement. We are using the same example to show demos for the print statement. Then another concatenation containing the “=” sign and another variable containing the value of the current element of the array.įollowing is the general syntax to use the print statement:Īs such, the print statement is almost like the PHP echo statement. After that, the string is concatenated by “.” followed by the variable name containing the key of associated array. In the demo, you can see first a string is used in the echo PHP statement. See the example by clicking the link or image below: Inside the foreach loop, the echo statement is used to display the array keys and element values. Then a foreach loop is used to iterate through array elements. In this example, an array is created with three elements. While in the single quoted string, the variable itself is displayed. for the double quoted text with and without parenthesis. You can see, in first two strings the variable name is replaced by the variable value i.e. The variable is used in three sentences with double quotes, double quoted with parenthesis and single quoted string. This is almost the same example as above except we used a variable inside the string. See online demo and code An echo example with variables See the code and output by clicking the link below: The first string is enclosed in double quotes and the second in double quotes with parenthesis while the third in the single quote. In the following example, three simple strings are displayed by using the echo statement. An example of displaying a string by echo
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |