array_is_list( array<mixed> $arr ): bool
- Since
- 6.5.0
- Source
wp-includes/compat.php:469
array_is_list() function added in PHP 8.1.Description
Determines if the given array is a list.
An array is considered a list if its keys consist of consecutive numbers from 0 to count($array)-1.
Compatibility
- WordPress
- since 6.5.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$arrarray<mixed>- The array being evaluated.
Return value
bool- True if array is a list, false otherwise.
Performance profile
How much work a call to array_is_list() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Scales with input
- Instructions
- 4–17
- Plugin surface
- None
- Called by
- 21
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 20.
Nothing here hands control to plugin code.
21 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost array_is_list() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$arr === false | 4 | none |
$arr !== false | 9–17 | array_values() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 20 instructions, 4–17 executed per call, 5 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Used by · 21
- AbstractOpenAiCompatibleImageGenerationModel::parseResponseToGenerativeAiResult()Parses the response from the API endpoint to a generative AI result.
- AbstractOpenAiCompatibleTextGenerationModel::parseResponseChoiceToCandidate()Parses a single choice from the API response into a Candidate object.
- AbstractOpenAiCompatibleTextGenerationModel::parseResponseToGenerativeAiResult()Parses the response from the API endpoint to a generative AI result.
- ModelConfig::setFunctionDeclarations()Sets the function declarations.
- ModelConfig::setOutputModalities()Sets the output modalities.
- ModelConfig::setStopSequences()Sets the stop sequences.
- ModelMetadata::__construct()Constructor.
- ModelRequirements::__construct()Constructor.
- PromptBuilder::isMessagesList()Checks if the value is a list of Message objects.
- PromptBuilder::parseMessage()Parses various input types into a Message with the given role.
- PromptBuilder::usingModelPreference()Sets preferred models to evaluate in order.
- ProviderModelsMetadata::__construct()Constructor.
Show all 21
- SupportedOption::__construct()Constructor.
- WP_Interactivity_API::data_wp_each_processor()Processes the `data-wp-each` directive.
- WP_Interactivity_API::evaluate()Evaluates the reference path passed to a directive based on the current store namespace, state and context.
- WP_Translation_File_PHP::var_export()Outputs or returns a parsable string representation of a variable.
- WP_View_Config_Data::list_item_identity()Resolves the identity used to match a list member against another.
- WP_View_Config_Data::merge_properties()Merges an incoming value into the current one, recursing by value shape.
- WP_View_Config_Data::remove()Removes named properties from the configuration, leaving the rest alone.
- WP_View_Config_Data::remove_properties()Removes the properties a spec names from the current value.
- WP_View_Config_Data::strip_nulls()Recursively drops every property whose value is `null` from a value.
Source code
function array_is_list( $arr ) { if ( ( array() === $arr ) || ( array_values( $arr ) === $arr ) ) { return true; } $next_key = -1; foreach ( $arr as $k => $v ) { if ( ++$next_key !== $k ) { return false; } } return true; }Changelog
Introduced in 6.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/compat.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.