News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Infinite Array of Numbers

Started by redlightblack, July 29, 2007, 09:39:24 PM

Previous topic - Next topic

redlightblack

Can some tell my how to indicate an infinite array of numbers?

The reason I'd like to know is because I'd need to add something like:

if (in_array($context['current_uid'], array('1', '2', '3')))
    $current_action = 'library';


only without having to list each and every number since there are well over a thousand of them and they are always changing.

Please help if you can...

IchBin™

Well you can't do infinite as that will throw PHP into a never ending loop. You can however create a counter and assign the counter to add the numbers to the array. Then check if the $user_info['id'] is found in the array. Not a php guru yet, so bare with me when if it doesn't work.


$group_id = array();

for($i = 0; $i <= 1000; $i++)
$group_id[] = $i;


Then you can use this in your code. (I'm assuming your checking for the user ID number.)
if (in_array($user_info['id'], $group_id))
    $current_action = 'library';

IchBin™        TinyPortal

redlightblack

That's a bit over my head. Yes, I admit it. I'm a noob  :'( I'm learning as I go but, that tends to leave gaps in what I know.

Okay, let forget the increasing numbers and just try for a range between 1 and 100,000. How would I go about something like that?

Rudolf

if ($user_info['id'] >= && $user_info['id'] <= 100000)
    
$current_action 'library';


If you want, you can use variables instead of numbers.

if ($user_info['id'] >= $low_limit && $user_info['id'] <= $high_limit)
    
$current_action 'library';


$low_limit and $high_limit can be set at run-time based on some conditions.
I will update all my mods in the next few weeks. Thanks for your patience.

SVG-Collapse (you need an SVG compliant browser)

redlightblack

Thanks to both IchBin and Rudolf. I've gotten both of these to work for me. Rudolf's code helped me to understand what IchBin had posted too.  ;D

I just wish that other forums I've visited were as helpful as everyone here has been. Thanks again guys!  :D

Advertisement: