3

Array as per below-

Array ( [1] => staff [2] => Name [3] => Email [4] => surname [5] => registrationno )

I want to add the new value in array after [3] = > 'Email'

What should I do?

3

2 Answers 2

1

use array_splice():

<?php

$array = array( 
    '1' => 'staff',
    '2' => 'Name',
    '3' => 'Email',
    '4'=> 'surname',
    '5' => 'registrationno',
);

array_splice($array, 3, 0, 'myvalue');

print_r($array);
Sign up to request clarification or add additional context in comments.

Comments

0

You can use array_splice();

$input = array ( [1] => staff [2] => Name [3] => Email [4] => surname [5] => registrationno ); array_splice($input, 3, 0, "myvalue"); //$input is now array ( [1] => staff [2] => Name [3] => Email [4] => myvalue [5] => surname [6] => registrationno );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.