← CodePrimer
PHP Beginner Basics

Declare a PHP function

How do I write a reusable function?

function keyword + return.

Sample
<?php
function greet(string $name): string {
  return 'Hello, ' . $name;
}
echo greet('Ada');

Notes

Type hints make intent clearer (PHP 7+).

Keywords: function · return · parameter

Related

Need more coins?

You do not have enough coins for this action.

Your balance: 0 coins

Share