Search
 
SCRIPT & CODE EXAMPLE
 

PHP

echo (PHP 4, PHP 5, PHP 7, PHP 8) echo — Output one or more strings

<?php
echo "echo does not require parentheses.";

// Strings can either be passed individually as multiple arguments or
// concatenated together and passed as a single argument
echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', "
";
echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . "
";

// No newline or space is added; the below outputs "helloworld" all on one line
echo "hello";
echo "world";

// Same as above
echo "hello", "world";

echo "This string spans
multiple lines. The newlines will be
output as well";

echo "This string spans
multiple lines. The newlines will be
output as well.";

// The argument can be any expression which produces a string
$foo = "example";
echo "foo is $foo"; // foo is example

$fruits = ["lemon", "orange", "banana"];
echo implode(" and ", $fruits); // lemon and orange and banana

// Non-string expressions are coerced to string, even if declare(strict_types=1) is used
echo 6 * 7; // 42

// Because echo does not behave as an expression, the following code is invalid.
($some_var) ? echo 'true' : echo 'false';

// However, the following examples will work:
($some_var) ? print 'true' : print 'false'; // print is also a construct, but
                                            // it is a valid expression, returning 1,
                                            // so it may be used in this context.

echo $some_var ? 'true': 'false'; // evaluating the expression first and passing it to echo
?>
Comment

PREVIOUS NEXT
Code Example
Php :: php convert datetime to timestamp 
Php :: fichier wp-config.php 
Php :: amazon linux 2 php.ini changes not working 
Php :: php sort multidimensional array by child value 
Php :: php questions in tasks 
Php :: drupal 9 custom access checking for routes 
Php :: selecting a time zone from a drop-down list 
Php :: Laravel: validate an integer field that needs to be greater than another 
Php :: Add custom column at custom posts list 
Php :: laravel firstorcreate with multiple parameters 
Php :: shop manager Redirect @ WooCommerce 
Php :: PHP DOMDocument, Unicode problems 
Php :: php browser cache clear 
Php :: set owner symfony 
Php :: x-default wpml canonical alternate hreflang 
Php :: haseeb php code 
Php :: contact form dropdown from post 
Php :: display page template using functions.php 
Php :: GZIP COMPRESSION With PHP 
Php :: instagram api error 
Php :: public function __sleep() and __wakeup() 
Php :: php only includable file 
Php :: php script 
Php :: laravel migration add column first 
Php :: create custom rule in laravel 
Php :: artisan command to add resources to controller 
Php :: get action name in yii2 
Php :: progress bar calculate percentage php 
Java :: java get screen size 
Java :: list java versions mac 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =