Print In PHP
Learning how to use PHP print effectively can help you write better code and debug your scripts more effectively, regardless of your level of PHP experience.
In our PHP tutorial the following is a complete guide to using PHP print function.
A PHP print function displays information on the web in a simple, yet versatile manner.
PHP print is a built-in function in PHP, a widely used server-side scripting language for web development. It is used to display output or data on a web page. The print statement is followed by the content that needs to be displayed, enclosed in parentheses or double quotes.
PHP print Function
The print function is a language construct in PHP that is used to output a string value to the browser.
Debugging or displaying the results of a calculation or query is frequently used.
PHP print is similar to echo, but it is a language construct rather than a function, so in some cases it is faster than echo.
Print has a very simple syntax:
The print can be used with or without parentheses: print or print().
PHP print Examples
Here is a simple example of how you can output text using the print (note that the text can be formatted in HTML markup):
With the print statement, you can output string and int through variables, as shown in the below examples:
In above example, several variables are created and then displayed using the print function.
The first two variables, $string1 and $string2, are string variables that store text.
The text in these variables is then concatenated with HTML tags using the . operator and displayed using the print function.
The last two lines of the PHP code create two variables, $a and $b, and assign them values of 4 and 7, respectively. The print function is then used to display the result of $a + $b, which is 11.
You can also use print to show the contents of arrays. Examples include:
Print function in PHP is commonly used for debugging purposes, since it displays values and checks a script’s output.
PHP print function is a simple, yet powerful tool for displaying information in a web-based environment. Whether you’re using it for debugging or simply to display the results of a calculation, print is an essential tool for every PHP developer to know. With its simple syntax and versatility, print is a handy tool to add to your PHP toolkit.