note 110690 added to mysqli-result.fetch-array

From: Date: Thu, 22 Nov 2012 23:41:49 +0000
Subject: note 110690 added to mysqli-result.fetch-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-192105@lists.php.net to get a copy of this message
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;} } ?> ---- Server IP: 94.76.225.145 Probable Submitter: 86.154.236.84 ---- Manual Page -- http://www.php.net/manual/en/mysqli-result.fetch-array.php Edit -- https://master.php.net/note/edit/110690 Del: integrated -- https://master.php.net/note/delete/110690/integrated Del: useless -- https://master.php.net/note/delete/110690/useless Del: bad code -- https://master.php.net/note/delete/110690/bad+code Del: spam -- https://master.php.net/note/delete/110690/spam Del: non-english -- https://master.php.net/note/delete/110690/non-english Del: in docs -- https://master.php.net/note/delete/110690/in+docs Del: other reasons-- https://master.php.net/note/delete/110690 Reject -- https://master.php.net/note/reject/110690 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#192105) next »