php - How can I make my function execute even when no parameter is entered? -
i'm teaching myself php through book , make easier made myself function save myself having write echo "<br/>";
million times. function works fine after accidentally leaving out parameter , getting error tried make if left function empty add 1 <br/>
can't seem work.
here code after last attempt (which try case null: echo "<br/>";
):
function br($break){ switch ($break){ case 1: echo "<br/>"; break; case 2: echo "<br/><br/>"; break; case 3: echo "<br/><br/><br/>"; break; case 4: echo "<br/><br/><br/><br/>"; break; case 5: echo "<br/><br/><br/><br/><br/>"; break; case null: echo "<br/>"; } }
any ideas? guys!
p.s. sorry if silly question, started learning php on monday , programming experience limited :)
try this:
function br($break = 1){ }
btw, case, can use:
echo str_repeat('<br />', 5);
which create 5 br's, take here: http://php.net/str_repeat
also, when in doubt something, first time check php.net documentation, there might function want already.
Comments
Post a Comment