Learn PHP Programming

A backend server scripting language, and a powerful tool for making dynamic and interactive Web pages. Learn each topic with examples and output.

PHP Introduction
Control Structures
Php Forms
Php Advanced

PHP Heredoc

In PHP, a Heredoc is a way to define strings that span multiple lines and can contain variables, making it an alternative to double-quoted strings (") for creating multiline strings. Heredoc syntax is useful when you need to include a large block of text or HTML within your PHP code. Here's the syntax for using Heredoc in PHP:

    $variable = <<<EOT
    This is a Heredoc string.
    It can span multiple lines.
    Variables like \$variable are interpolated: $variable.
    EOT;
    

Here's a breakdown of the Heredoc syntax:

<?php
$name = "Alice";
$age = 30;

$message = <<<EOT
Hello, my name is $name.
I am $age years old.
EOT;

echo $message;
?>
Hello, my name is Alice.
I am 30 years old.
    

In next chapter is CRUD operations in php


Share this page on :

=