如何檢查PHP數組是關聯數組仍是順序數組? - How to check if PHP array is associative or sequential?

問題:

PHP treats all arrays as associative, so there aren't any built in functions. PHP將全部數組視爲關聯數組,所以沒有任何內置函數。 Can anyone recommend a fairly efficient way to check if an array contains only numeric keys? 誰能推薦一種至關有效的方法來檢查數組是否僅包含數字鍵? 數組

Basically, I want to be able to differentiate between this: 基本上,我但願可以區分如下二者: app

$sequentialArray = array('apple', 'orange', 'tomato', 'carrot');

and this: 和這個: 函數

$assocArray = array('fruit1' => 'apple', 
                    'fruit2' => 'orange', 
                    'veg1' => 'tomato', 
                    'veg2' => 'carrot');

解決方案:

參考一: https://stackoom.com/question/j6m/如何檢查PHP數組是關聯數組仍是順序數組
參考二: https://oldbug.net/q/j6m/How-to-check-if-PHP-array-is-associative-or-sequential
相關文章
相關標籤/搜索