מספרים שלמים

מספר שלם הוא מספר מהקבוצה Z = { ... , -2 , -1 , 0 , 1 , 2 ,.. . } .

ראה גם : מספרים שלמים בעלי אורך שרירותי ו - מספרים בעלי נקודה צפה .

Syntax

דוגמה 6-1 .

 
$a

 
=

 
1234

 
;

 
#

 
decimal

 
number

 
$a

 
=

 
-123

 
;

 
#

 
a

 
negative

 
number

 
$a

 
=

 
0123

 
;

 
#

 
octal

 
number

 
(equivalent

 
to

 
83

 
decimal

 
)

 
$a

 
=

 
0x1A

 
;

 
#

 
hexadecimal

 
number

 
(equivalent

 
to

 
26

 
decimal

 
)



The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed). PHP does not support unsigned integers.

Integer overflow

 
$large_number

 
=

 
2147483647

 
;

 
var_dump($large_number)

 
;

 
/

 
/

 
output

 
:

 
int(2147483647

 
)

 
$large_number

 
=

 
2147483648

 
;

 
var_dump($large_number)

 
;

 
/

 
/

 
output

 
:

 
float(2147483648

 
)

 
/

 
/

 
this

 
goes

 
also

 
for

 
hexadecimal

 
specified

 
integers

 
:

 
var_dump

 
(

 
0x80000000

 
)

 
;

 
/

 
/

 
output

 
:

 
float(2147483648

 
)

 
$million

 
=

 
1000000

 
;

 
$large_number

 
=

 
50000

 
*

 
$million

 
;

 
var_dump($large_number)

 
;

 
/

 
/

 
output

 
:

 
float(50000000000

 
)



אזהרה



 
var_dump(

 
25

 
/

 
7

 
)

 
;

 
/

 
/

 
output

 
:

 
float(3.5714285714286

 
)





Converting to integer

However , in most cases you do not need to use the cast , since a value will be automatically converted if an operator , function or control structure requires a integer argument .

From floating point numbers

אזהרה

 
echo

 
(

 
int

 
)

 
(

 
(0.1+0.7

 
)

 
*

 
10

 
)

 
;

 
/

 
/

 
echoes

 
7

 
!



See for more information the warning about float-precision .

From other types

זהירות

However , do not relay on this behaviour , as it can change without notice .