Update Array Items in PHP

You can update array items by assigning a new value to an existing index or key.

Example of Updating Array Items

<?php
$colors = array("red", "green", "blue");
$colors[0] = "yellow";
print_r($colors);

$person = array("name" => "John", "age" => 30);
$person['age'] = 31;
print_r($person);
?>

Output:

Array
(
    [0] => yellow
    [1] => green
    [2] => blue
)
Array
(
    [name] => John
    [age] => 31
)

Explanation: This example demonstrates how to update array items in PHP by assigning a new value to an existing index or key.