Jump to content

Returning Many Variables From A Function


Selacius
 Share

Recommended Posts

I have a sequence of code, roughly 50-75 lines long of if statements checking a variable to base values and then changing other variables depending on which base value it matches.Ex.if ($a == "Socks"){$socks = $socks + 1;}elseif ($a == "Hat"){$hat = $hat + 1;}This sequence continues for about another 10 if statements. Now this lengthy piece of code is found 2 separate times in the page depending on previous decisions made in the code. I want to make it into a function that way I don't have to worry about it increasing the length of my code and if i need to change or add something, I have to do it to one sequence and not 2. Now some of you may wonder why i need it in two separate spots but i've tried it other ways but it didn't work. My main issue is how I can have it return the values from the actual if statement. I know I can have return $socks or return $hat, and then when calling the function I can do $func = clothing ();. But I just want to be able ot return the values and after calling the function do an echo $socks and if $a == "Socks" then it would display a 1.I hope you understand what I am asking.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...