Home >Backend Development >PHP Problem >How to replace array value in php
How to replace array values in php: You can use the array_replace() function to replace. The array_replace() function replaces the values of the first array with the values of the second array and returns the replaced array, or NULL if an error occurs.
array_replace() function replaces the value of the first array with the value of the subsequent array and returns the replaced array, or NULL if an error occurs.
(Recommended tutorial: php graphic tutorial)
Syntax:
array_replace(array1,array2,array3...)
Parameters:
array1 Required. Specify an array.
array2 Optional. Specifies an array to replace the value of array1 .
array3,... Optional. Specify multiple arrays to replace the values of array1 and array2, ... . The values in the following array will overwrite the values in the previous array.
(Video tutorial recommendation: php video tutorial)
Example:
Use the second array ($a2) Replace the value of the first array ($a1) with the value.
<?php $a1=array("red","green"); $a2=array("blue","yellow"); print_r(array_replace($a1,$a2)); ?>
The above is the detailed content of How to replace array value in php. For more information, please follow other related articles on the PHP Chinese website!