0

So in the base PHP Functions (probably not a good reference but anyway) example, the function array_push($arr, $info) - you can put as many items in the $info variable as you want, but example if you don't put in a paramater in a function that you made, example public function __connstruct($conn_string, $drivers), how would one want to achieve making the $drivers variable not needed unless the function is called with it.

Is it a special type of variable in the function?

2
  • default argument values?! Commented Apr 8, 2016 at 21:29
  • refer the function func_get_args Commented Apr 8, 2016 at 21:33

1 Answer 1

2

Try this: default arguments

public function __construct($conn_string, $drivers = null)
{
  // do something
}

This makes $drivers an optional function argument

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much, I feel so stupid now but thanks for answering anyway :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.