PHP Important 5 Syntax

I will be talking about PHP. I’m going to be introducing this series where we will be learning a lot about what PHP. And so forth if you have no idea what PHP is and you just either you’re being forced to learn. It for a job or you want to learn it. I’m going to be explaining what PHP is a programming language. It’s what’s known as a server-side and I’ll get into that in a minute.

So mainly PHP is used to develop websites it can be used to create a shell programs through shell applications through. The command line but we’re not going to be getting into that. We’re going to be developing websites with PHP so I’m actually going to erase this beautiful content. PHP is a programming language to develop dynamic websites and that you can use it as an interface to connect to a database.

 

 

PHP Basic Syntax

Start writing PHP crate or open file with the (dot)php file extension technically. This isn’t actually required but if you want things like syntax highlighting an IDE. That type names or variable names functions. example : Hello World!

We can generally want to name your files with a particular file extension. But then also with PHP all the PHP code that we write in that file has to be enclosed in these PHP delimiters.

That we see here on the screen angle bracket question mark PHP. Then we write all of our PHP code that we want in between and then question mark angle bracket – close if we don’t do this.

———***————

<!DOCTYPE html>

<html>

<body>

<h1>My first PHP page</h1>

<?php

echo “Hello World!”; ?>

 </body></html>

———***————

PHP Variables

Start out variables PHP variables exist they’re just two big differences from C. All that stuff we don’t do that anymore PHP is a modern language.  What you’re trying to

do! variable names most to start with a dollar sign ($). It’s just something to get used to it’s a little weird it’s that PHP can understand what’s a variable. And what’s not every variable name starts with a dollar sign C we might say something like this int $x=52 we’d have.

<?php
$txt = “Hello world!”;
$x = 52;
?>

PHP Array

PHP arrays are not fixed in size. You can mix data types in our arrays too, we don’t even have to use all integers or all floating points.

We can have a mix of all different kinds in a single array declaring an array is pretty straightforward just like any other variable dollar sign ($) nums equals array 1,2,3,4.

Array being a function that’s built into PHP that will create an array for you this creates an array of 4 values numbers in this case called dollar sign ($) number.

<?php
$test = array(“1”, “2”, “3”, “4”);
echo “I like ” . $test[1] . “, ” . $test[2] . ” , ” . $test[3] . “, ” . $test[2] . ” .”;
?>

echo and print Statements
It a couple of different ways you might have noticed the two functions we’ve primarily seen our print and echo for pretty much all intents.
And purposes they’re exactly the same very subtle difference. I personally uses echo as well. Otherwise you can use print option.

print
<?php
print “<h2>PHP  Learn!</h2>”;
print “Hello world!<br>”;
?>

echo
<?php
echo “<h2>PHP  Learn!</h2>”;
echo “Hello world!<br>”;
?>

PHP Functions

PHP can handle function. We sort of integral to C as we saw like variables. No need specify the return type of the function. because it doesn’t really matter and we don’t need to specify the data types of any parameters.
With the function keyword that’s how we indicate to PHP interpreter works from top to bottom regardless. if it seesn you make a function call it’ll go find the function call even if it comes later how we create a function like-:

<?php
function helloMsg() {
    echo “Hello world!”;
}

helloMsg(); // call the function
?>

I have realized that PHP basic 5 works. If you have any problems understanding, of course your comments please.

Thank you.

Leave a Reply

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


TechinfoHQ © 2019