Defualt Argument

wxdqz

New Member
let s consider this function

function tour_guide($city = \"Gotham City\",
$desc = \"vast metropolis\",
$how_many = \"dozens\",
$of_what = \"costumed villains\")
{
print(\"$city is a $desc filled with
$how_many of $of_what.<BR>\");
}
tour_guide();
tour_guide(\"Chicago\");
tour_guide(\"Chicago\", \"wonderful city\");
tour_guide(\"Chicago\", \"wonderful city\",
\"teeming millions\");
tour_guide(\"Chicago\", \"wonderful city\",
\"teeming millions\",
\"gruff people with hearts of
gold and hard-luck stories to tell\");

If for example i want to change the 3rd argument without writing the rest of the argument (give them the default value)

One of the solution that i found is to set it us the 1st agrument

eg.
function tour_guide($how_many = \"dozens\" /* ex 3rd*/,$city = \"Gotham City\",$desc = \"vast metropolis\", $of_what = \"costumed villains\")

but if some times i want to change 2 argements then 2 others
i couldn t find a solution
(beginer)
 
Back
Top