How to Write Functions in PHP
PHP has a huge collection of built-in functions that you can call directly from within a script to perform a task. It's also possible to write your own custom functions in PHP. Functions are blocks of code that can be used over and over again, accept input from the caller, process the data, and return a value.
Usually, when you're creating a new function, you have to tell PHP what type it should be. This is called typing, and it allows PHP to automatically assign the variable a data form, so you can do things like add strings or integers without causing an error.
Since PHP 7.0, you've been able to use type hinting for function arguments. You specify the type of data that a function expects to receive by adding a colon and the desired type before the opening curly (
You can even apply the same concept to function returns, which are the values returned from a function. However, this is not something that you can do in all contexts, because PHP will not allow you to return null for a function that is nested inside of another function. You'll need to use a type hint for this, and you'll need to pass the argument as an array, not a string.