php move element to beginning of array 1

php move element to beginning of array

$array = array("JS", "JAVA");
array_unshift($array, "PHP");
print_r($array);
// Add More Than One Element
$array1 = array("JS", "JAVA");
array_unshift($array1, "PHP", "CSS", "HTML");
print_r($array1); // => { PHP CSS HTML JS JAVA }

Here is what the above code is Doing:
1. First, we created an array with two elements.
2. Then, we added a new element at the beginning of the array using array_unshift() function.
3. Finally, we printed the array.

The output of the above code will be:
Array ( [0] => PHP [1] => JS [2] => JAVA )

Similar Posts