ID: 13679 Updated by: sander Reported By: [EMAIL PROTECTED] Old Status: Feedback Status: Closed Bug Type: Arrays related Operating System: Slackware 8.0 PHP Version: 4.0.6 New Comment:
No feedback. Closing. Previous Comments: ------------------------------------------------------------------------ [2001-10-15 19:23:40] [EMAIL PROTECTED] status -> feedback ------------------------------------------------------------------------ [2001-10-15 18:45:19] [EMAIL PROTECTED] Can you please provide a short stand-alone script exhibiting the problems? Try to use only array(), array_unique() and var_dump() functions, and in any case no functions like mysql_query(). (there exists a 'null' keyword, for if you need it) ------------------------------------------------------------------------ [2001-10-15 18:32:27] [EMAIL PROTECTED] Creating a mysql database that holds a field of values, e.g. TLDs, with row 0 containing cx nu com org net, row 1 containing it at de us com, and so forth, a semi-annoying bug can be created with array_unique() that will insert null elements into the new array. For example: <? $connection = mysql_connect("localhost","classicgames","classicgames"); mysql_select_db("classicgames",$connection); $query = "select votes from tldvote"; $result = mysql_query($query); $i = 0; while($row = mysql_fetch_row($result)) { $string = implode("",$row); $tempArray = explode(" ",$string); for($j = 0; $j < 5; $j++) { $votes[$i][$j] = $tempArray[$j]; } $i++; } for($i = 0, $k = 0; $i < sizeOf($votes); $i++) for($j = 0; $j < 5; $j++) { $type[$k] = $votes[$i][$j]; $k++; } /* Bug is created here, just this script alone will produce an array of unique types as well as null (more-so towards "") types. */ $tempType = array_unique($type); for($i = 0; $i < sizeOf($type); $i++) for($j = 0; $j < sizeOf($tempType); $j++) if($type[$i] == $tempType[$j]) $tally[$j] = $tally[$j] + 1; array_multisort($tally, SORT_DESC,$tempType); for ($i = 0; $i < sizeOf($tally); $i++) echo $tempType[$i]." has ".$tally[$i]." votes.<br>"; ?> Now, I was able to fix this by adding: <? for($i = 0; $i < sizeOf($tempType); $i++) if($tempType[$i] == NULL) { array_push($tempType,$i); array_pop($tempType); } ?> which simply takes the new unique array and pushes null values to the top, then pops them out of the array. Configure line: './configure' '--disable-debug' '--with-config-file-path=/usr/local/apache/conf' '--with-mysql=/usr/local/mysql' '--prefix=/usr/local/php4' '--with-apxs=/usr/local/apache/bin/apxs' '--enable-track-vars' '--with-xml' '--enable-track-errors' '--enable-force-cgi-redirect' '--enable-discard-path' '--enable-safe-mode' '--enable-calendar' '--with-jpeg-dir=/usr/local' '--with-png-dir=/usr/local' '--with-gd=/usr' '--enable-gd-native-tt' '--with-zlib-dir=/usr/local' '--with-zlib' '--enable-trans-sid' '--enable-ftp' '--with-png-dir=/usr/local' '--with-gettext' '--enable-memory-limit' '--with-mcrypt' '--with-mcrypt-dir=/usr' '--with-pspell-dir=/usr/local/pspell' If any other information is required, just write an e-mail back. ------------------------------------------------------------------------ Edit this bug report at http://bugs.php.net/?id=13679&edit=1 -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]