Click here to Skip to main content
15,898,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a code with 100 variables, which I'm thinking I must have made them arrays, even though I keep having problems with it. I'm still learning.
variables are
variable1, variable2, variabl3, and so on.
So depending on what the user submits, ,let's say 3. Gives the total from variable 4 to 100.

Thanks a lot for your time and help!

What I have tried:

I have tried making variables and making infinite "ifs" but there's gotta be a better way.
Posted
Updated 29-Mar-17 8:24am
Comments
Dave Kreskowiak 29-Mar-17 13:27pm    
There's nothing to help with here. We know nothing about your code at all, other than the statement "I have a code with 100 variables", which makes an experienced person cringe. If you've got 100 variables for anything, you've got a MASSIVE design problem that will only be solved by scraping the code and rewriting with a better design.

1 solution

PHP
$a = array(1, 2, 3, 4, 5 ... 98, 99, 100);
$b = array_slice($a, 3);
$c = array_sum($b);

All written here:
PHP: Arrays - Manual[^]
PHP: Array Functions - Manual[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900