bigBA
January 7th, 2005, 11:04 AM
we have some functions at work to connect and query our backend.
so i searched a little bit in its sourcecodes (i wanted to duplicate a function and modify it a bit) and i discovered one thing, that i do not fully understand or rather i think that they are equivalent.. but i think there must be some kind of cause for this.
the function i mentioned creates an option list out of two arrays (one for the values and one for the displayed texts).
and in addition a value, which should be marked as <selected>.
there are two ways the function will work, either you supply two arrays or just one. in the last case, the value and text informations are taken from the key and the value of the array.
so in the first case comparison of the selected value is done in this way:
if( ((string)$value[$i]===(string)$selected) )
//......
in the second case, comparison is done like this:
if( $key == $selected )
//....
as i understand "==" compares just the values, not the type so 1 as string should match against 1 as an integer. well.. it does :)
and "===" compares value and type. so that 1 as string would not match against 1 as integer.
but... as you see in the code listing above the two values are casted to string before the "===" operation... so 1 as string, casted to string, will match against 1 as int, casted to string....
or not? - what is the difference?? :ehh: :ehh:
so i searched a little bit in its sourcecodes (i wanted to duplicate a function and modify it a bit) and i discovered one thing, that i do not fully understand or rather i think that they are equivalent.. but i think there must be some kind of cause for this.
the function i mentioned creates an option list out of two arrays (one for the values and one for the displayed texts).
and in addition a value, which should be marked as <selected>.
there are two ways the function will work, either you supply two arrays or just one. in the last case, the value and text informations are taken from the key and the value of the array.
so in the first case comparison of the selected value is done in this way:
if( ((string)$value[$i]===(string)$selected) )
//......
in the second case, comparison is done like this:
if( $key == $selected )
//....
as i understand "==" compares just the values, not the type so 1 as string should match against 1 as an integer. well.. it does :)
and "===" compares value and type. so that 1 as string would not match against 1 as integer.
but... as you see in the code listing above the two values are casted to string before the "===" operation... so 1 as string, casted to string, will match against 1 as int, casted to string....
or not? - what is the difference?? :ehh: :ehh: