How to insert a new item in an array in any position with PHP

1 Answer

0 votes
$arr = array(1, 2, 3, 'c', 4, 'php' );

$value = 'www';
array_splice($arr, 4, 0, $value); 

foreach ($arr as $item) { 
    echo "$item ";
}



/*
run:

1 2 3 c www 4 php 
 
*/

 



answered Mar 1, 2019 by avibootz

Related questions

3 answers 201 views
1 answer 179 views
1 answer 203 views
1 answer 197 views
1 answer 197 views
2 answers 204 views
2 answers 272 views
...