Hi Dev,
Today, i we will show you php string concatenate, variable and array example. This article will give you simple example of php string concatenate, variable and array example. you will learn php string concatenate, variable and array example.
Php is provided to the two types of Concatenation (“.”),(‘.=’) to
So let’s follow few step to create example of php string concatenate, variable and array example.
(“.”) Operator
The dot concatenation operator in PHP concatenate right and left arguments.
(‘.=’) Operator
This second concatenation operator helps in the expansion of the right side argument to the left side argument.
Concatenate Two Strings & Variables In PHP Example
<?php $string1 = 'John'; $string2 = 'shina'; $name_str = $string1 . ' ' . $string2; echo $name_str; ?>
Output:
John shina
Concatenating Variable With String In PHP Example
<?php $var = "Hello"; echo $var.' World'; ?>
Output:
Hello World
Concatenate Two Arrays In PHP Example
<?php $myArr = array(1, "tv" => "ac", 2, "washing machine", 3); $mySecondArr = array("word", "abc", "vegetable" => "tomato", "state" => "washington dc"); $output = array_merge($myArr, $mySecondArr); print_r($output); ?>
Output:
Array ( [0] => 1 [tv] => ac [1] => 2 [2] => washing machine [3] => 3 [4] => word [5] => abc [vegetable] => tomato [state] => washington dc )
Now you can check your own.
I hope it can help you…