How to add element at the beginning of an array in PHP

1 Answer

0 votes
$arr = array("php", "java", "python", "c", "c++");
 
array_unshift($arr, "c#");

print_r($arr);





/*
run:

Array
(
    [0] => c#
    [1] => php
    [2] => java
    [3] => python
    [4] => c
    [5] => c++
)

*/

 



answered Jun 19, 2022 by avibootz

Related questions

1 answer 165 views
1 answer 172 views
1 answer 229 views
1 answer 189 views
...