What is the basic syntax of PHP? Explain with example

May 7, 2023 · Team EasyExamNotes · 1 min read (est.) · 0 comments

Share on WhatsApp

PHP, which stands for Hypertext Preprocessor, is a server-side scripting language used for developing dynamic web applications.

Here is the basic syntax of PHP:

<?php
// PHP code goes here
?>

The opening tag indicates the end of PHP code. All PHP code goes between these tags.

Here is an example of PHP code that uses variables:

<?php
$firstName = "Kunal";
$lastName = "Shinde";
$age = 18;

echo "My name is " . $firstName . " " . $lastName . " and I am " . $age . " years old.";
?>

In this example, we declare three variables: $firstName, $lastName, and $age. We then use the echo statement to output a string that includes the values of these variables. The . operator is used to concatenate the strings and variables together.

When this code is executed, it will output the following text:

My name is Kunal Shinde and I am 18 years old.

This is just a basic example, but PHP has many more features and functions that allow developers to build complex web applications.

Discussion

Ask a question, share your thoughts or report an error.

Sign in to participate in the discussion.

Join the discussion