note 110690 deleted from mysqli-result.fetch-array by googleguy
| From: | googleguy@php.net | Date: | Thu, 22 Nov 2012 23:57:03 +0000 |
| Subject: | note 110690 deleted from mysqli-result.fetch-array by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192106@lists.php.net to get a copy of this message | ||
Note Submitter: ricardof1rst3
----
For a bizarre reason I need both arrays, indexed and associative but I also wish to 'pass
on' the associations to another array. I decided that I didn't want to run two queries
given I already had all the data in the returned array. It took me a while to work out that the
array was twice as long as it should be if looping through (so use sizeof($x)>>1). In the end
I created the below routine which I hope is of use to someone else, call with output from
mysqli_fetch_array (both) and set flag ($f) as false for indexed array and true for associative.
<?php
function mysqlSplitArray($a,$f)
{
$i=0;
foreach ($a as $k=>$e)
{
$i?$x[$k]=$e:$y[$k]=$e;
$i=~$i;
}
if ($f) {return $x;} else {return $y;}
}
?>