Core PHP

Passing Arguments via Arrays

This PHP code is an example program that demonstrates how to write functions and pass in their arguments via arrays in PHP.

FunctionsPassingArgumentsViaArrays.php

<?php

  // This is function takes in three arguments and returns an equation.
  function EquationOfSum(int $iA1, int $iA2, int $iA3) : string {
    return $iA1." + ".$iA2." + ".$iA3." = ".($iA1 + $iA2 + $iA3);
  }

  // Call the function with an array of values.
  $iaArray1 = array(16, 34, 27);
  echo EquationOfSum(...$iaArray1)."<br />";

  // Call the function with three values.
  echo EquationOfSum(83, 53, 19)."<br />";

?>
 

Output

 
 

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