Home  >  Article  >  Backend Development  >  How to replace array value in php

How to replace array value in php

王林
王林Original
2020-08-11 13:58:223153browse

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.

How to replace array value in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn