Please leave a comment If you found BROKEN LINK OK, thanks for visit my website,...!!!

Shooter Game Chrome PC Free Download Shooter Game Angels Fall First: Planetstorm PC Download Harvest Moon - Back To Nature PC Game Download Download PC Game TMNT 2 : Battle Nexus RIP MediaFire Prince Of Persia Warrior Within Download PC Game Resident Evil 2 img 1 metal slug super vehicle Devil May Cry 3 Portable Cool Game Download

Search


PHP Functions With Parameters | Lombok Study

Another useful thing about functions is that you can send them information that the function can then use. Our first function myCompanyMotto isn't all that useful because all it does, and ever will do, is print out a single, unchanging string.
However, if we were to use parameters, then we would be able to add some extra functionality! A parameter appears with the parentheses "( )" and looks just like a normal PHP variable. Let's create a new function that creates a custom greeting based off of a person's name.
Our parameter will be the person's name and our function will concatenate this name onto a greeting string. Here's what the code would look like.

PHP Code with Function:

<?php
function myGreeting($firstName){
echo "Hello there ". $firstName . "!<br />";
}
?>

When we use our myGreeting function we have to send it a string containing someone's name, otherwise it will break. When you add parameters, you also add more responsibility to you, the programmer! Let's call our new function a few times with some common first names.

PHP Code:
<?php
function myGreeting($firstName){
echo "Hello there ". $firstName . "!<br />";
}
myGreeting("Jack");
myGreeting("Ahmed");
myGreeting("Julie");
myGreeting("Charles");
?>

Display:
Hello there Jack!
Hello there Ahmed!
Hello there Julie!
Hello there Charles!

It is also possible to have multiple parameters in a function. To separate multiple parameters PHP uses a comma ",". Let's modify our function to also include last names.

PHP Code:
<?php
function myGreeting($firstName, $lastName){
echo "Hello there ". $firstName ." ". $lastName ."!<br />";
}
myGreeting("Jack", "Black");
myGreeting("Ahmed", "Zewail");
myGreeting("Julie", "Roberts");
myGreeting("Charles", "Schwab");
?>

Display:
Hello there Jack Black!
Hello there Ahmed Zewail!
Hello there Julie Roberts!
Hello there Charles Schwab!

Related Post

0 komentar:

Posting Komentar