Doc #62383 [Com]: array_replace() arguments not passed by reference

From: Date: Fri, 22 Jun 2012 10:53:08 +0000
Subject: Doc #62383 [Com]: array_replace() arguments not passed by reference
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-8494@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62383&edit=1 ID: 62383 Comment by: fd@php.net Reported by: confidential99 at gmail dot com Summary: array_replace() arguments not passed by reference Status: Open Type: Documentation Problem Package: Arrays related PHP Version: Irrelevant Block user comment: N Private report: N New Comment: You have to use $array1 = array_replace($array1,$array2,$array3); if you want your expected result. This is not a bug but the expected behaviour as stated in the documentation for array_replace(). Previous Comments: ------------------------------------------------------------------------ [2012-06-21 14:27:17] confidential99 at gmail dot com Description: ------------ The document for the array_replace function says that "array_replace() replaces the values of the first array with the same values from all the following arrays...." The signature for the function indicates the arrays will be passed by reference. Test script: --------------- <?php $array1 = array('AMZN'=>223.02,'BA'=>8.14,'SAN'=>6.26,'AAPL'=>586.05); $array2 = array('AMZN'=>223.84,'BA'=>8.11,'SAN'=>6.40,'FB'=>31.60,'ORCL'=>28.49); $array3 = array('AMZN'=>224.25,'BA'=>8.10,'ORCL'=>28.39,'INTC'=>27.38); array_replace($array1,$array2,$array3); var_dump($array1); Expected result: ---------------- array(7) { ["AMZN"]=> float(224.25) ["BA"]=> float(8.1) ["SAN"]=> float(6.4) ["AAPL"]=> float(586.05) ["FB"]=> float(31.6) ["ORCL"]=> float(28.39) ["INTC"]=> float(27.38) } Actual result: -------------- array(4) { ["AMZN"]=> float(223.02) ["BA"]=> float(8.14) ["SAN"]=> float(6.26) ["AAPL"]=> float(586.05) } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62383&edit=1

« previous php.doc.bugs (#8494) next »