PHP Variables

Back to ACP page

Table of Contents

PHP Creating Variables

<h2>Creating_Variables</h2> <p>In PHP, a variable starts with the $ sign, followed by the name of the variable: </p> <?php $x = 5; $y = "John"; echo $x; echo "<br>"; echo $y; ?>

Example 1

Result View Example

PHP Output Variables

<h4>php-Output_Variables</h4> <p>From w3schools.com, Experiment by Teeratus_R </p> <?php $txt = "W3Schools.com"; echo "I love $txt!"; echo "<br>"; echo "<hr>"; echo "I love " . $txt . "!"; echo "<hr>"; $x = 5; $y = 4; echo $x + $y; ?>

Example 2

Result View Example

PHP Get the Type

<h4>php-Get_the_Type</h4> <p>From w3schools.com, Experiment by Teeratus_R </p> <pre> <?php var_dump(5); var_dump("John"); var_dump(3.14); var_dump(true); var_dump([2, 3, 56]); var_dump(NULL); ?> </pre>

Example 3

Result View Example

PHP Assign Multiple Values

<h4>Assign_Multiple_Values</h4> <p>You can assign the same value to multiple variables in one line:</p> <?php $x = $y = $z = "Fruit"; echo $x; echo "<br>"; echo $y; echo "<br>"; echo $z; ?>

Example 4

Result View Example

Document

Document in project

You can Download PDF file.

Reference