Short answer : Yes, it is possible to use a flag in a user-defined function.
In a nutshell, A flag uses cases are three :
- a built in function flag
- a PHP extension function flag
- a user defined function flag
A built in php function, you can see that:
echo PREG_OFFSET_CAPTURE."<br>";// output 256
A php exntesion, when installed, you could use its constants, as if they were core php functions flags,
If you want to define your own flags for your own function, you can :
define ("LETTER", "letters");
define ("NUMBER", "numbers");
function newFootnote($text,$flag){
if ($flag==NUMBER){
// code to display foot notes as numbers
echo "The numbers are :$text <br />";
}elseif($flag==LETTER){
// code to display foot notes as letters
echo "The letters are :$text <br />";
}else{
// choose between a default behavior, or rising an error
echo "error <br />";
}
}
newFootnote (" some random text to test", NUMBER); // output The numbers are : some random text to test
newFootnote (" some random text to test", LETTER); // output The letters are : some random text to test
newFootnote (" some random text to test",NULL); // error
However, I would prefer to use the format: newFootnote(LETTER) or newFootnote(NUMBER)
actually you can't call it that way, because you have got to provide the first parameter that is the $text, you'll call it that way:
newFootnote($text,LETTER);//or
newFootnote($text,NUMBER);
If you want to hide the constants definition and/or make them available in your programs then you can put them in a file (ideally with the function definition) and include it when needed, let that file be notesFunctions.php, put in it:
define ("LETTER", "letters");
define ("NUMBER", "numbers");
function newFootnote($text,$flag){
if ($flag==NUMBER){
// code to display foot notes as numbers
echo "The numbers are :$text <br />";
}elseif($flag==LETTER){
// code to display foot notes as letters
echo "The letters are :$text <br />";
}else{
// choose between a default behavior, or rising an error
echo "error <br />";
}
}
then in your program, depending on the location of the files (here assuming they are in the same folder), you put :
include ("notesFunctions.php");
/* then you call your function as needed and the output still be the same as
before */
newFootnote (" some random text to test", NUMBER); // output The numbers are : some random text to test
newFootnote (" some random text to test", LETTER); // output The letters are : some random text to test
newFootnote (" some random text to test",NULL); // error