LMSouq
php-dev Open

How to check if PHP array is associative or sequential?

WI
Wilco
1 month ago
3 views
Problem Description
PHP treats all arrays as associative, so there aren't any built in functions. Can anyone recommend a fairly efficient way to check if an array *"is a list"* (contains only numeric keys starting from 0)? Basically, I want to be able to differentiate between this: $sequentialArray = [ 'apple', 'orange', 'tomato', 'carrot' ]; and this: $assocArray = [ 'fruit1' => 'apple', 'fruit2' => 'orange', 'veg1' => 'tomato', 'veg2' => 'carrot' ];

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base