Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.