Tuesday, April 22, 2025

PHP Default Arguments

You are advised to check corresponding YouTube video at the end of this article.


<?php 

function one_ping($host = "google.com") {
	echo "<pre>";
	system ("ping ". $host);
	echo "</pre>";
}

one_ping("yahoo.com");

?>

The function "one_ping" has a default argument of "google.com" assigned to the parameter $host. This means that if an argument is not passed when the function is called, it will use "google.com" as the default value for the $host parameter.

Using default arguments in functions can be useful in situations where you want to provide a default value for a parameter, but still allow the user to override it if needed. This can make the function more flexible and easier to use.

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...