Understanding PHP Functions

I am beginner in programmer, can anyone describe to me how php function work? I have searched any tutorial but I am still confusing..

Why this function doesn’t work?

<?php
$name = "Maria";
$gender = "Female";
$country = "Thailand";

function profile(){
   echo $name . "<br>";
   echo $gender . "<br>";
   echo $country . "<br>";
}
profile()
?>

Or like this:

<?php
function data(){
   $name = "Maria";
   $gender = "Female";
   $country = "Thailand";
}
function profile(){
   echo $name . "<br>";
   echo $gender . "<br>";
   echo $country . "<br>";
}
data();
profile()
?>

Posted by Surya Infotech

Leave a Reply