2

I have a function with multi parameters and I want to call it in several places in my code. How can I call it with some default values like:

Addhistory($h_id, $h_name, $user_id=0, status=true)

So user_id and statue will have default values when we will not pass it?

Thanks.

4
  • ($h_id,$h_name,$user_id=0,status=true) this will do same what you want. isn't it? Commented Feb 5, 2016 at 13:13
  • 1
    Answer is already there in your question :) Commented Feb 5, 2016 at 13:15
  • H.H.e please check my answer i elaborated for you. if useful then mark and up-vote the answer. Commented Feb 26, 2016 at 5:13
  • peoples are not interested in telling problem solved or not? wastage of effort. Deleting my answer. Commented Mar 21, 2016 at 17:43

2 Answers 2

1

This is the right way, by assigning $user_id=0 and $status=true you are defining their defaults.

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

Comments

0

1.Defining the function

function Addhistory($h_id, $h_name, $user_id=0, $status=true){
    //do something with parameters
}

2.Calling the function with default argument values.

Addhistory(1,'example_string')//you need to just pass $h_id and $h_name as arguments if you want to call the function with default argument values.

default argument values

Comments

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.