function

Estimated reading time: 1 minute

function

function user() {
  echo("function name isn't case-sensitive");
}
user();
User();
# function name isn't case-sensitive

argument

function user($name,$status) {
  echo("${name} is a ${status}");
}
user("kamal","coder");
# kamal is a coder

default argument

function user($name,$status="artist") {
  echo("${name} is a ${status}");
}
user("kamal");
# kamal is a artist

rest

function user(...$users) {
  echo $users[1];
}
user(5,7,6);
# 7

call function inside another function


class Worker{
  public function user(){
    return "this is user";
  }
  public function employee(){
    //call coba function
    return $this->user();
  }

}

$klass = new Worker();
echo $klass->employee();
php