Get function arguments values PHP
I have a function with 5 arguments and default site width variable
$site_width ='1000px';
function MyPrintFunction ($divName,$width=false,$html1='',$html2='', $echo = true ){
... plenty of code above, no need to post complete function
$html = '<div id="'.$divName.'">';
$html .= '</div>';
if( $echo ){
echo $html1.$html.$html2;
}else{
return $html1.$html.$html2;
}
}
and than I print html like:
MyPrintFunction ('divname1',true);
MyPrintFunction ('divname2');
MyPrintFunction ('divname3');
I need to check if any of these functions has set the second argument to true, and if yes , I need first argument name.
This way I can add the argument name to css snippet ( will be injected in head later ) and set width for it
#ARrument1NameSHouldGoHereAsVariable{
width:$site_width;
}
I hope I explained this right. Sorry if I did not. Any help is appreciated. Thank you!
Answer
Solution:
Noo no no, you absolutely can have optional arguments. It's a bit messy of a situation, but totally possible.
The reason it is discouraged is because... Let's suppose you want to set a height, but not a width to 435
Optional arguments should generally not be used, and if they are to place them at the end in an array
Please oh please let this be what you are seeking...
Answer
Solution:
What's this for?
The logic goes like this