Creating Your First Program Using PHP

If you are PHP programmer, then, you may want to know about how to create your first program using the PHP programming language. It has many different way to display the output of the program written in PHP language. So, in order for your help, we are creating the first PHP program for you. It has different methods for the same purpose(ie. same output, here, in our PHP program shown below, the output is always Hello World, by using the different methods available in the PHP programming) and the respected comments in the same code below shows about their details. The code for creating your first program using PHP programming language is given below:

<?php
// creating your first program using php
echo "Hello World!<br />"; // the easiest and direct way of displaying the output
print "Hello World!<br />"; // works same as echo

/* display the result by using the variable */
$a = "Hello World!<br />";
echo $a;

/* display the result by using the concatenation method */
$a = "Hello ";
$b = "World!<br />";
echo $a . $b;

/* display the result by using the concatenation method using the variable in concatinated form */
$a = "Hello ";
$b = "World!<br />";
$c = $a;
$c .= $b;
echo $c;
?>
first-php-program

The above image is the result of the above programming code when it is executed. Here, in the above program, we have used the PHP function echo and print to display the result directly, which is kept inside the double inverted comma. And in the second one, we have assigned a string in the variable $a and displayed it with echo. And, in the third one, we have created two variables, $a and $b and displayed them by combining those, which is also the feature of PHP programming language. And lastly, we have assigned three variables, $a$b and $c where we have assigned the $c to $a and concatenated with $b.

Now, we can assume that, if you have followed the above instructions properly, we can say that you now know how to display the content using the PHP programming language easily than before.

Post navigation

Bishal Napit

Bishal Napit is a WordPress theme developer from Tansen, Palpa, with a passion to learn more on WordPress.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.