PHP diziler için değer kopya vs referans?

0 Cevap

Ben belirgin bir şey eksik. Burada hata ayıklama ekolar ile çevrili PHP önemsiz bir parça bulunuyor:

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);
}

İşte yanıtı görmek ne:

0
0
3
3
13
13
182
182
---.---
4
182
182
182
182

Bana öyle çok açık görünüyor: -

Herkes Ben (bir ilişkisel dizidir) $ satırın bir kopyasını almak için yapmanız gereken herhangi bir fikrin var mı?

Teşekkürler.

EDIT: çoğunuz $ isimli, burada sınıf res ne olduğunu bilmek için çok ısrarlı olduğu. Ben gerçekten bu (benim OP dolayısıyla ihmal) aydınlatmak daha şaşırtmak için daha muhtemel olduğuna inanıyoruz.

class mysqlie_results {
    private $stmt;
    private $paramArray= array(); 
    private $assocArray= array(); 

    kamu function __construct(&$stmt) {
        $this->stmt= $stmt;
        $meta= $stmt->result_metadata(); 

        while ($colData= $meta->fetch_field()) {
            $this->paramArray[]= &$this->assocArray[$colData->name]; 
        }

        call_user_func_array(array($stmt,'bind_result'),$this->paramArray); 
        $meta->close(); 
    } 

    kamu function __destruct() {
        $this->stmt->free_result();
    } 

    kamu function fetch() { 
        return $this->stmt->fetch()? $this->assocArray : false;
    } 
} 

0 Cevap