09.
Optional Function Arguments
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
6 Comments
Just realised that the sql query you write that is held by the $query variable inside the if statement needs to be spaced or else you will get errors.
Its a small realization but it took me a while to correct since my code and the tutors code were identical and just the space was the issue.
$query=$query.' LIMIT '.$limit; //(WHEN WRITING LIMIT--LEAVE A SPACE AFTER AND BEFORE THE INVERTED COMMAS..
Hey Not.available_X,
Yeah, you're absolutely right! We do have those spaces around the LIMIT word, but it's easy to miss :) Thanks for focusing attention on this tricky part of the code.
Cheers!
When you assign the argument with a value of null. How would the if statement ever become true in the scope of the function?
Would not the parameter's value be overwritten by the argument always?
1. function test(param = null){ //Wouldn't the null value will overwrite the paramater's value which is 3 (line 7)?
2. if (param==true)
3. { //How would this ever become true? }
4. }
5.
6. //function call
7. test(3);
Hey Haris R.
Whenever you define a function argument as follows:
what it does is to define the default value of the
$paramargument. So, it allows you to call the test function as followsI hope it makes sense to you :)
Cheers!
Yepp.. Got it! Should've been explained in the tutorial as it is for the beginners
Oh, you are right, sorry for the confusion. At least I could answer your doubts :)
"Houston: no signs of life"
Start the conversation!