Jump to content

Function help


MetalSmith

Recommended Posts

Ok I was told to get a variable from a function you need to do something like this:

 

 

function scale($quantity)

 

{

 

  if ($quantity <= 4500) $interval = 1000;

  if ($quantity <= 2250) $interval = 500;

  if ($quantity <= 900) $interval = 200;

  if ($quantity <= 450) $interval = 100;

  if ($quantity <= 225) $interval = 50;

  if ($quantity <= 90) $interval = 20;

 

  return $interval;

 

}

 

$interval = scale ($some_number);

 

 

But what if I want to get more variables from a function like below?

 

 

function scale($quantity)

 

{

 

  if ($quantity <= 4500)

 

  {

 

  $interval = 1000;

  $a = 25;

  $b = 75;

  $c = 150;

 

  )

 

  if ($quantity <= 2250) $interval = 500;

  if ($quantity <= 900) $interval = 200;

  if ($quantity <= 450) $interval = 100;

  if ($quantity <= 225) $interval = 50;

  if ($quantity <= 90) $interval = 20;

 

  return $interval;

 

}

 

$interval = scale ($some_number);

 

I need $a, $b, $c

Link to comment
https://forums.phpfreaks.com/topic/168840-function-help/
Share on other sites

Arrays are your friend.

 

function scale($quantity)

{
  $a = $b = $c = 0; // default the values to 0
   if ($quantity <= 4500) {

   $interval = 1000;
   $a = 25;
   $b = 75;
   $c = 150;

   }

  if ($quantity <= 2250) $interval = 500;
  if ($quantity <= 900) $interval = 200;
  if ($quantity <= 450) $interval = 100;
  if ($quantity <= 225) $interval = 50;
  if ($quantity <= 90) $interval = 20;

  return array($interval, $a, $b, $c);

}

list($interval, $a, $b, $c) = scale ($some_number);

 

Something like that should work. list

Link to comment
https://forums.phpfreaks.com/topic/168840-function-help/#findComment-890827
Share on other sites

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.