3 Ways to Insert Values into an Array at a Specific Position Using PHP

Written by Ubaidullah| PHP

In this tutorial, I’m going to demonstrate three ways to insert values with keys into an array at a specific position using PHP.

Table of Contents

  1. Method 1
  2. Method 2
  3. Method 3

Suppose, we have two arrays with numeric and associative keys:

Method 1

Here, I’m going to insert an element with a key after third array element.


Method 2

This method would work with arrays with numeric keys.


Method 3

This method would work for both: numeric and associative arrays.

3 Ways to Insert Values into an Array at a Specific Position Using PHP
Rate this post

Last modified: June 16, 2017

Leave a Reply

Your email address will not be published. Required fields are marked *