Jump to content

how to return multiple values from a function


ivytony

Recommended Posts

Or return an object:

 

<?php

function multiValues($number1, $number2) {

  $vals->average = ($number1+$number2)/2;
  $vals->max = ($number1>$number2)?$number1:$number2;
  $vals->min = ($number1<$number2)?$number1:$number2;
  return $vals;

}

$values = multiValues(5, ;

echo $values->average;
echo $values->max;
echo $values->min;


//Output:
// 6.5
// 8
// 5
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.