Solved

max number

Posted on 2008-09-29
5
200 Views
Last Modified: 2008-09-29
hello there,
I have this code but I would like to know what will be the max number I can have.. as of now I have it set to 151
will it be possible to have it over millions or it will take up high loads on the server and memory?
$checkthisnumber = '50';
 
$i=1;
while ($i < 151) 
{
        
 if ($i == $checkthisnumber) 
        {
                echo $checkthisnumber . ' number found';
                break;
        }
$i++;
}

Open in new window

0
Comment
Question by:XK8ER
  • 4
5 Comments
 
LVL 7

Expert Comment

by:ahalya
ID: 22595757
Well, it depends on the type of "i"

if you are looking for smaller ranges then use byte or word

If the type of i is

byte: 0..255  (8 bit)
word: 0..65535 (16 bit)

You can have much larger ranges by using integer, longint, cardinal etc. See Delphi's help file for the ranges.

The loop takes longer to execute with a higher number, but there is no concern in terms of memory.  
0
 
LVL 7

Accepted Solution

by:
ahalya earned 500 total points
ID: 22595767
From Delphi Help:

Shortint      -128..127      signed 8-bit
Smallint      -32768..32767      signed 16-bit
Longint      -2147483648..2147483647      signed 32-bit
Int64      -2^63..2^63-1      signed 64-bit
Byte      0..255      unsigned 8-bit
Word      0..65535      unsigned 16-bit
Longword      0..4294967295      unsigned 32-bit
0
 
LVL 7

Expert Comment

by:ahalya
ID: 22595802
ouch, sorry. I thought I was in the Delphi forum.  For php, the maxsize is dependent on the platform. but in most cases it will be 32-bits.

Which is to say that you can go from -2147483648 to 2147483647. (in most cases)

0
 
LVL 7

Expert Comment

by:ahalya
ID: 22595811
Also, you can use PHP_INT_MAX to determine the maximum size of the integer.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 22597108
@XK8ER: You can count up to very high numbers, but I am curious... What is the intended purpose of the example you posted above?  It looks like it is just loops, adding one until it comes to (drum roll) a number you ALREADY KNOW!  Please tell us a little more about your objectives.

To answer your direct question, yes it will place a load on the processor, and no, it will not place a load on memory.

See the man page here for info on largest integers:
http://us3.php.net/manual/tr/reserved.constants.php
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question