0

I have some PHP variables whose names are directly linked to the function they contain.

Is there anyway of automating the creation of these variables, so that I can ALL variables 00-200 available for use?

This is what I'm doing now...

$regdays00 = is_user_reg_matured( 00 );
$regdays02 = is_user_reg_matured( 02 );
$regdays05 = is_user_reg_matured( 05 );
$regdays08 = is_user_reg_matured( 08 );

I'd love to be able to go:

small function that creates all $redays000 - $regdays200

if ( $regdays162) { "This has now used is_user_reg_matured(162)" }

Thank you!

5
  • 4
    Just No! Don't do that. Use arrays or something else, but don't create freaking 200 variables just with an incrementing number. Commented Jun 9, 2016 at 3:20
  • 1
    why in the world would you create that many variables, just use an array Commented Jun 9, 2016 at 3:21
  • I'm not familiar with arrays... can you give me an example? Commented Jun 9, 2016 at 3:23
  • 1
    @Scott Google PHP array and PHP for and read the manual page. These are some basic stuff so make sure you really understand them :) Your code will be way better that way. Commented Jun 9, 2016 at 3:28
  • Thank you so much! Commented Jun 9, 2016 at 3:34

1 Answer 1

1

This is begging for a basic loop and an array.

Something like this perhaps:

$regdays = [];
for($i = 0; $i < 200; $i++) {
    $regdays[$i] = is_user_reg_matured($i);
}

There you go. An array of 0 - 199.

if ($regdays[162]) { 
    echo "This has now used is_user_reg_matured(162)";
}

I highly recommend you do some reading up on arrays and loops. These are some basic PHP tools you very much need in your toolbelt!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.