Modify existing values in a PHP array

This tutorial explains how to modify existing values in a PHP array. It’s pretty simple – all you need to do is refer to the array and its index and then change that index’s value with another value.

Watch the video below and then scroll down to see the sample code.

Sample PHP code:

<?php
  // create a simple array with 12 elements inside it
  $months = array("January","February","March","April","May","June","July","August","September","October","November","December");
  
  // change the value of the second element in the array
  $months[1] = "Feb";

  // return the value of the second element in the arrray
  echo $months[1];
?>