![Oh cacchio! [acc2]](http://www.megalab.it/forum/images/smilies/Acc.gif)
- Codice: Seleziona tutto
$mac="ff";
$mac==0; //Questa ritorna VERO!!
$mac=="0"; //Questa ritorna (giustamente) FALSO!
Un baco da segnalare oppure una mia lacuna culturale? propendo per la seconda
![Fragorosa risata [:D]](http://www.megalab.it/forum/images/smilies/fragorosa_risata.gif)
$mac="ff";
$mac==0; //Questa ritorna VERO!!
$mac=="0"; //Questa ritorna (giustamente) FALSO!
Manuale di M@ttia ha scritto:Converting to boolean
To explicitly convert a value to boolean, use either the(bool) or the (boolean) cast. 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 boolean argument.
When converting to boolean, the following values are considered FALSE:
• the boolean FALSE
• the integer 0 (zero)
• the foat 0.0 (zero)
• the empty string, and the string "0"
• an array with zero elements
• an object with zero elements
• the special type NULL (including unset variables)
Every other value is considered TRUE (including any resource).
Manuale di M@ttia ha scritto:String conversion
When a string is evaluated as a numeric value, the resulting value and type are determined as follows:
The string will evaluate as a foat if it contains any of the characters . , e , or E. Otherwise, it will evaluate as an integer.
The value is given by the initial portion of the string. If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 (zero). Valid numeric data is an optional sign, followed by one or more digits (optionally containing a decimal point), followed by an optional
exponent. The exponent is an e or E followed by one or more digits.
When the first expression is astring, the type of the variable will depend on the second expression.
$foo=1+"10.5"; //$fooisfloat(11.5)
$foo=1+"-1.3e3"; //$fooisfloat(-1299)
$foo=1+"bob-1.3e3"; //$fooisinteger(1)
$foo=1+"bob3"; //$fooisinteger(1)
$foo=1+"10SmallPigs"; //$fooisinteger(11)
$foo=1+"10LittlePiggies"; //$fooisinteger(11)
$foo="10.0pigs"+1; //$fooisinteger(11)
$foo="10.0pigs"+1.0; //$fooisfloat(11)
Manuale PHP ha scritto:If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 (zero).
Lo so, sono un genio stesso!M@ttia ha scritto:Eheh, quando ho visto che avevi risposto anche tu credevo volessi solo congratularti con lo Zane per aver usato la Variabile chiamata $mac
Zane ha scritto:Grazie mille per il chiarimento!
Però, se posso fare una critica... in un linguaggio loosely typed come PHP mi sarei aspettato un comportamento diverso!
Visitano il forum: Nessuno e 3 ospiti
megalab.it: testata telematica quotidiana registrata al Tribunale di Cosenza n. 22/09 del 13.08.2009, editore Master New Media S.r.l.; © Copyright 2008 Master New Media S.r.l. a socio unico - P.I. 02947530784. GRUPPO EDIZIONI MASTER Spa Tutti i diritti sono riservati. Per la pubblicità: Master Advertising