MetalSmith Posted August 4, 2009 Share Posted August 4, 2009 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 More sharing options...
premiso Posted August 4, 2009 Share Posted August 4, 2009 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 More sharing options...
MetalSmith Posted August 4, 2009 Author Share Posted August 4, 2009 Yea I think that will work just fine. Thanks alot man!! Link to comment https://forums.phpfreaks.com/topic/168840-function-help/#findComment-890840 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.