Your First Function Codeacademy PHP Example

Your First Function Codeacademy PHP Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<html>
	<head>
		<title></title>
	</head>
	<body>
      <p>
        <?php
        // Write your function below!
        function displayName()
            {
                echo "Hello Cristi.";   
            }
        displayName();
 
        ?>
      </p>
    </body>
</html>

Functions are very easy in PHP.

As you can notice, the syntax is “function name() – where the () contains the paramenters. And you need to open brackets {} just like you do for while, for, an if/else statement.

An easy way to memorize the syntax is to imagine a road like this:

1
2
3
 {
         echo '';
 }

Echo is the road.

Add a comment: