Reference vs. value copy for PHP arrays?

veraswanee

New Member
I am missing something obvious. Here's a trivial piece of PHP, littered with debug echos:\[code\]function echo_rows(&$res) { $rows= array(); while ($row= $res->fetch()) { echo $row['ccorID'] . "\r\n"; $rows[]= $row; echo $rows[0]['ccorID'] . "\r\n"; } echo "---.---\r\n"; echo count($rows) . "\r\n"; foreach($rows as $row) { echo $row['ccorID'] . "\r\n"; } echo json_encode($rows);}\[/code\]Here's what I see in the response:\[code\]00331313182182---.---4182182182182\[/code\]It seems perfectly clear to me that :-Anyone got any idea what I need to do to get a copy of $row (which is an associative array)?Thanks.EDIT: Since many of you are so insistent to know what $res is, here is the class. I genuinely believe that this is more likely to confuse than enlighten (hence the omission from my OP).\[code\]class mysqlie_results { private $stmt; private $paramArray= array(); private $assocArray= array(); public function __construct(&$stmt) { $this->stmt= $stmt; $meta= $stmt->result_metadata(); while ($colData= http://stackoverflow.com/questions/3568496/$meta->fetch_field()) { $this->paramArray[]= &$this->assocArray[$colData->name]; } call_user_func_array(array($stmt,'bind_result'),$this->paramArray); $meta->close(); } public function __destruct() { $this->stmt->free_result(); } public function fetch() { return $this->stmt->fetch()? $this->assocArray : false; } } \[/code\]
 
Back
Top