Home >Backend Development >PHP Problem >How to output two values ​​in php

How to output two values ​​in php

zbt
zbtOriginal
2023-07-10 16:14:441314browse

How to output two values ​​in php: 1. Use the echo statement; 2. Use the print statement; 3. Use the printf function; 4. Use the print_r function; 5. Use the var_dump function.

How to output two values ​​in php

The operating environment of this tutorial: windows10 system, php8.1.3 version, DELL G3 computer.

There are many ways to output two values ​​in PHP. Below we will introduce some commonly used methods.

1. Use echo statement:

$value1 = 'Hello';
$value2 = 'World';
echo $value1, ' ', $value2; // 输出:Hello World

2. Use print statement:

$value1 = 'Hello';
$value2 = 'World';
print $value1 . ' ' . $value2; // 输出:Hello World

3. Use printf function:

$value1 = 'Hello';
$value2 = 'World';
printf("%s %s", $value1, $value2); // 输出:Hello World

4. Use print_r function :

$data = array('Hello', 'World');
print_r($data); // 输出:Array ( [0] => Hello [1] => World )

5. Use the var_dump function:

$value1 = 'Hello';
$value2 = 'World';
var_dump($value1, $value2); // 输出:string(5) "Hello" string(5) "World"

These methods can be used to output different types of values ​​such as strings, arrays, objects, etc. You can choose the most appropriate method to output the two values ​​according to your needs.

The above is the detailed content of How to output two values ​​in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn