note 89427 deleted from function.array-slice by danbrown
| From: | danbrown@php.net | Date: | Thu, 28 Oct 2010 16:07:00 +0000 |
| Subject: | note 89427 deleted from function.array-slice by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173560@lists.php.net to get a copy of this message | ||
Note Submitter: uncleneg at yahoo dot com
----
You should regard this!: 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. :)