Of course if you need to print formatted variables in a PHP string you'll want to go with printf, or perhaps sprintf, but for other PHP variable printing needs, echo and print are just fine. As a final note, if
print_variable.php <?php declare(strict_types=1); $name = "John Doe"; $age = 32; print "Name: $name, Age: $age"; The code demonstrates variable interpolation in strings with print. Variables are automatically converted to strings when printed. Double quotes allow variable values to be ...
Usevar_dump()Function to Echo or Print an Array in PHP Thevar_dump()function is used to print the details of any variable or expression. It prints the array with its index value, the data type of each element, and length of each element. It provides the structured information of the ...
To print multiple variables using theprint()function, we need to provide the variable names as arguments separated by the commas. Note:print()function prints space after the value of each variable, space is the default value ofsep parameter– which is an optional parameter inprint() function, ...
Printing an Array in PHP To print or echo an array in PHP, you can use the print_r($variable, $return) or var_dump($variable1, $variable2, ...) functions. The print_r() function prints information about the passed variable in human-readable form. The first parameter is the "varia...
ExampleRun this code » <?php // Defining variable $str1 = "Hi There"; $str2 = "Have a nice day"; // Printing variables values print $str1 . "! " . $str2 . " :)"; // Above statement can also be written as print "$str1! $str2 :)"; ?>...
// the variable goes till it finds // the closing word "EOF;" (it can also be renamed) $test =<<<EOF This is an example of an long variable. You can also put {$some_variables} in here :-) EOF; // ^ do not use any spaces in the line above (just "EOQ;") // sprintf...
multiple lines with$variableinterpolation. Note that the here document terminator must appear on a line with just a semicolon. no extra whitespace! END;//echo 与 print区别$some_var=true; ($some_var) ?echo'true':echo'false';// PHP报错($some_var) ?print'true':print'false';// true//...
<?php$string='Learn PHP Echo';print"<PRE>";echo"Hello World! \$string\n\n";echo"PHP echo prints the value in the variable \"str\":$string\n\n";echo"Hello\nWorld!\nLearnPHP\n\n";?> Echo statement with single vs double quotes ...
<?php $a =array("red","green","blue"); print_r($a); echo""; $b =array("Peter"=>"35","Ben"=>"37","Joe"=>"43"); print_r($b); ?> Try it Yourself » Definition and Usage The print_r() function prints the information about a variable in a more human-readable way. ...