如何检查PHP数组是关联数组还是顺序数组?
PHP将所有数组视为关联数组,因此没有任何内置函数。任何人都可以推荐一种相当有效的方法来检查数组是否“是一个列表”(仅包含从0开始的数字键)?
基本上,我希望能够区分这一点:
$sequentialArray = [
'apple', 'orange', 'tomato', 'carrot'
];
和这个:
$assocArray = [
'fruit1' => 'apple',
'fruit2' => 'orange',
'veg1' => 'tomato',
'veg2' => 'carrot'
];