Outputting the Value of a Variable

suggest change

Introduction

To build a dynamic and interactive PHP program, it is useful to output variables and their values. The PHP language allows for multiple methods of value output. This topic covers the standard methods of printing a value in PHP and where these methods can be used.

Remarks

Variables in PHP come in a variety of types. Depending on the use case, you may want to output them to the browser as rendered HTML, output them for debugging, or output them to the terminal (if running an application via the command line).

Below are some of the most commonly used methods and language constructs to output variables:

Note: When trying to output an object as a string, PHP will try to convert it into a string (by calling __toString() - if the object has such a method). If unavailable, an error similar to Object of class [CLASS] could not be converted to string will be shown. In this case, you’ll have to inspect the object further, see: outputting-a-structured-view-of-arrays-and-objects.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Outputting the value of a variable:
* Outputting the Value of a Variable

Table Of Contents
2 Arrays
4 Types
10 Cookies
14 JSON
15 SOAP
17 cURL
19 XML
21 Traits
35 UTF-8
36 URLs
38 PHPDoc
41 Loops
44 Closur
72 YAML
77 Cache
78 Streams
81 PDO
82 SQLite3
83 Sockets
84 Outputting the value of a variable
87 MongoDB
93 IMAP
94 Redis
95 Imagick
102 APCu
108 PSR