Combining Two Strings in PHP

If we want to combine/concatenate two strings in PHP we just follow some special type of operators in PHP you can also see that In Other language we use + operator as a concatenation of two words but in PHP we use Dot Operator to concatenate two words. Here is the example you understand better.

  • We have declared two variables and assign the first and last name then after we take a new variable and concatenate first name and last name and then we print the message variable which show the concatenation of two variable.

    concatenation of two variable

Join Paragraphs Using here doc Syntax

If we have big paragraph now which are breaks in many variable now if we want to concatenate/combine all the variables its take time basically in this way heredoc syntax make our work easier:

  • We easily concatenate words evens paragraph but some different strategy by declaring some addition syntax.
  • We only put “” and put all the variables names in it. Here is the best example to understand the syntax and we must follow this syntax.

    $heredoc= <<< EOT;
    //Paragraph body and varibale
    EOT;
    Echo $heredoc;

    declared two variables

Storing Multiple Values In Array

In C# language you declare an array which store multiple values. In PHP If you want to store a multiple values in array you follow this syntax:

  • First we declare a character variable and then we make an array of two names it is not mandatory to put only two names its depend upon you.

  • Then we use special method in PHP to see the array values which we store on it and also give the index of array along with it.

    index

Associative Array

In PHP the associative array is different from simple array because in simple array you give an index of array and access its value but associative array you declare an array which is handle by string.

  • You can’t directly access associative array if you access it then error is display.

    display

  • It store multiple value in single variable.

    Program

Challenge For New Developers?

How PHP Embed In HTML?

  • It’s difficult but now you change the mind because programming have no boundaries.
  • Print this two things which is show in below using PHP and embedded in HTML.
  • Hint: Make Simple array and one Associative Array.
  • Then embedded in HTML Body.

    run

Here’s the solution

You can see that we make an array one is simple array and one is associative array in PHP then we call at HTML first we giving the tag of PHP then give the array name now set the value one and then we out concatenate operator for good looking and after this we simple called variable array and set the array index to ready a value.

Code

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now