How to Replace Value By Key in PHP Array?

03-Apr-2023

.

Admin

How to Replace Value By Key in PHP Array?

Hi Dev,

This tutorial is focused on how to replace value by key in a PHP array. you'll learn how to replace value by key in the array of PHP. We will use how to replace value by key in the PHP array. if you have a question about how to replace value by key in the array then I will give a simple example with a solution.

Now, let's see the article on how to replace value by key in the PHP array. it's a simple example of how to replace value by key in the array of PHP. you can understand the concept of how to replace value by key in an array of PHP. if you have a question about how to replace value by key in an array of PHP then I will give a simple example with a solution.

Example:


index.php

<?php

$array1 = array(0=>1, 1=>2);

$array2 = array(0=>0);

// Replace array

$newArray = array_replace($array1, $array2);

print_r($newArray);

?>

Output:

Array (

[0] => 0

[1] => 2

)

I hope it could help you...

#PHP