Re: Comparison Oddity

From: Date: Thu, 30 Nov 2000 18:42:03 +0000
Subject: Re: Comparison Oddity
Groups: php.general 
Request: Send a blank email to php-general+get-28093@lists.php.net to get a copy of this message
>The numeric value of 'date' is 0, but the type is string; which does not >match the numeric type of 0. > >Are you sure you set $column to '0', and not to 0? When I tried it: No, not positive. Here's the code in question: while ( $record = mysql_fetch_array( $result ) ) { while ( list($field, $value) = each($record) ) { if ( $field === "date" ) { $record[date] = date( 'F j, Y', $record[date] ); break; } } $testimonials[] = $record; } Basically, I'm taking a record array drawn from a MySQL query result and checking it for the existence of a value with the key "date." If it's there, I change the value from a standard UNIX date value to a human-readable string. With three "=" (testing type as well as value), it works as expected. With only two "=" (testing just for value equality), the "if" expression evaluates true when $field is 0 (which is there due to a 'feature' of mysql_fetch_array). The end result of this is that the date is "converted" twice (no bueno -- date value ends up UNIX "beginning of time" minus one second). Paul

« previous php.general (#28093) next »