1. array_shift() function
Deletes the first element in the array and returns the value of the element. Returns null if the array is empty.
Example:
<code><span><?php</span><span>$test_arr</span> = <span>array</span> ( <span>"name"</span> => <span>"jeanphorn"</span>, <span>"skill"</span> => <span>"programming"</span>, <span>"hobby"</span> => <span>"swimming"</span>, ); <span>echo</span> array_shift(<span>$test_arr</span>). <span>"\n"</span>; print_r(<span>$test_arr</span>); <span>?></span></span></code>
Result:
jeanphorn
Array (
[skill] => programming
[hobby] => swimming )
Note: If the key name is numeric, all elements will get new key names, starting from 0 and increasing by 1
2. array_pop() function
Delete the last element in the array. Returns null if the array is empty.
Example:
<code><span><?php</span><span>$test_arr</span> = <span>array</span> ( <span>"name"</span> => <span>"jeanphorn"</span>, <span>"skill"</span> => <span>"programming"</span>, <span>"hobby"</span> => <span>"swimming"</span>, ); <span>echo</span> array_pop(<span>$test_arr</span>). <span>"\n"</span>; print_r(<span>$test_arr</span>); <span>?></span></span></code>
The above introduces PHP to delete the first element and the last element of an array, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.