0

Is it possible call a function, whatever the parameter isset or not,
how to do it?

select();
select($response_message);

function select($response_message) {
  ....
}
Ram
  • 143,282
  • 16
  • 168
  • 197
user1775888
  • 3,147
  • 13
  • 45
  • 65

1 Answers1

1

For PHP, when you declare the function, put in a default value

function select($response_message = 'whatever') {
    ....
}

At this point, select() and select('whatever') run the same thing.

for more information on PHP

As for javascript, that process is a little more involved

Community
  • 1
  • 1
castis
  • 8,154
  • 4
  • 41
  • 63
  • Thanks for reply, in php what if the $response_message sometime is an array, can I define it before function like, $response_message = array(...); function select($response_message = $response_message') { – user1775888 Nov 11 '14 at 23:28
  • If you need to pass in an array, you can just run it like you'd expect `select(array('foo', 'bar'))`. 'whatever' is only assigned if you leave out the argument when you call it. – castis Nov 11 '14 at 23:30
  • As for attempting to assign a default value like that, you'll need to do all that inside the function declaration itself, cant do `function select($this = $that) {}`. – castis Nov 11 '14 at 23:33
  • so is it means I set function select($a = 'default') {} and other side I can call function like select() or $a = 'custom' select($a) – user1775888 Nov 11 '14 at 23:36