1. array_shift()函數
刪除數組中第一個元素,並傳回該元素的值。如果數組為空則傳回null。
範例:
<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>
結果:
jeanphorn
Array (
[skill] => programming
[hobby] => swimming )
注意: 如果鍵名是數字的,所有元素都會獲得新的鍵名,從 0 開始,並以 1 遞增
2. array_pop()函數
2. array_pop()函數
<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>
').text(i)); }; $numbering.fadeIn(1700); }); });
以上就介紹了PHP 刪除數組第一個元素和最後一個元素,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。
🎜 🎜