Skip to content

Comments

ext/standard: Add is_assoc_array() to detect associative arrays#21266

Closed
arshidkv12 wants to merge 1 commit intophp:masterfrom
arshidkv12:is_assoc_array
Closed

ext/standard: Add is_assoc_array() to detect associative arrays#21266
arshidkv12 wants to merge 1 commit intophp:masterfrom
arshidkv12:is_assoc_array

Conversation

@arshidkv12
Copy link
Contributor

Introduce a new core function is_assoc_array() that determines whether
an array is associative based on internal storage. The implementation
uses HT_IS_PACKED for fast O(1) detection.

Packed arrays are treated as non-associative, while hash-based arrays
are considered associative.

@devnexen
Copy link
Member

That looks very much RFC material to me

@arshidkv12
Copy link
Contributor Author

arshidkv12 commented Feb 21, 2026

@devnexen
Copy link
Member

just my personal take on this. Not sure how useful it really is, e.g. array_is_list()

@devnexen
Copy link
Member

nevermind, Bob already mentioned it :)

@arshidkv12
Copy link
Contributor Author

Thank you

@arshidkv12 arshidkv12 closed this Feb 21, 2026
@devnexen
Copy link
Member

try to take note from the discussion, if you want to do a proposal next time

The fact that this RFC doesn't even mention PHP's already available native
function (array_is_list() - which performs the inverse) indicates that this
initiative is under-researched.

Cheers.

@arshidkv12
Copy link
Contributor Author

What is your opinion on https://wiki.php.net/rfc/array_only_except?

@devnexen
Copy link
Member

devnexen commented Feb 21, 2026

it is a better selling point, you can live without still tough. Reading the discussion, some people already mention array_intersect_key and array_diff_key. Not sure that is good enough to be added in standard but I do not represent php all myself maybe other people have different opinions :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants