Core PHP

Functions with Arguments and Return Types

This PHP code is an example program that demonstrates how to write functions with argument and return types in PHP.

FunctionsWithArgumentAndReturnTypes.php

<?php

  // This function has designated types for both the arguments and the return value.
  // These can be enforced with a strict designation.
  function EquationWithTypes(int $iValue1, int $iValue2) : string {
    return $iValue1." + ".$iValue2." = ".($iValue1 + $iValue2);
  }

  // Call the function to return an equation string.
  echo EquationWithTypes(10, 6)."<br />";

?>
 

Output

 
 

© 2007–2025 XoaX.net LLC. All rights reserved.