note 89257 deleted from function.array-slice by danbrown

From: Date: Sat, 28 Feb 2009 17:27:20 +0000
Subject: note 89257 deleted from function.array-slice by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-151256@lists.php.net to get a copy of this message
Note Submitter: uncleneg at yahoo dot com ---- THIS IS A BIG SUCK!: FOR EXAMPLE: $result is a simple SQL table with Fieldname1, Fieldname2, Fieldname3 and values in first row 'val1', 'val2', 'val3': Case 1: $row=$mysqli_fetch_row($result,MYSQL_NUM); $mystring=implode('',array_slice($row,0,3)); echo $mystring; //will be: 'val1val2val3' this is OK. Case 2: Only you are changing MYSQL_NUM to MYSQL_BOTH: $row=$mysqli_fetch_row($result,MYSQL_BOTH); $mystring=implode('',array_slice($row,0,3)); echo $mystring; //will be: 'val1val1val2' this can be a big problem Explain: In Case2 $row will be: $row = { [0] => 'val1' [Fieldname1] => 'val1' [1] => 'val2' [Fieldname2] => 'val2' [2] => 'val3' [Fieldname3] => 'val3' } then array_slice will also collect Array Keys Fieldname1..3 with 0..2 one after the other unfortunately. My opinion: If $row would be the following after a mysql_fetch: $row = { [0] => 'val1' [1] => 'val2' [2] => 'val3' [Fieldname1] => 'val1' [Fieldname2] => 'val2' [Fieldname3] => 'val3' } then this problem doesn't happen. :)

« previous php.notes (#151256) next »