wp_array_slice_assoc( array $input_array, array $keys ): array
- Since
- 3.1.0
- Source
wp-includes/functions.php:5024
Compatibility
- WordPress
- since 3.1.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
$input_arrayarray- The original array.
$keysarray- The list of keys.
Return value
array- The array slice.
Performance profile
How much work a call to wp_array_slice_assoc() 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
- 6–7
- Plugin surface
- None
- Called by
- 27
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 13.
Nothing here hands control to plugin code.
27 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_array_slice_assoc() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 6–7 | none |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 13 instructions, 6–7 executed per call, 3 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 · 27
- WP_Comment_Query::fill_descendants()Fetch descendants for located comments.
- WP_Comment_Query::get_comment_ids()Used internally to get a list of comment IDs matching the query vars.
- WP_Comment_Query::get_comments()Get a list of comments matching the query vars.
- WP_Customize_Manager::import_theme_starter_content()Imports theme starter content into the customized state.
- WP_Customize_Manager::set_autofocus()Sets the autofocused constructs.
- WP_Customize_Nav_Menu_Item_Setting::sanitize()Sanitize an input.
- WP_Customize_Nav_Menu_Setting::sanitize()Sanitize an input.
- WP_Customize_Nav_Menu_Setting::update()Create/update the nav_menu term for this setting.
- WP_Customize_Nav_Menu_Setting::value()Get the instance data for a given widget setting.
- WP_Customize_Panel::json()Gather the parameters passed to client JavaScript via JSON.
- WP_Customize_Section::json()Gather the parameters passed to client JavaScript via JSON.
- WP_Network_Query::get_networks()Gets a list of networks matching the query vars.
Show all 27
- WP_Script_Modules::get_marked_for_enqueue()Retrieves the list of script modules marked for enqueue.
- WP_Site_Query::get_sites()Retrieves a list of sites matching the query vars.
- WP_Term_Query::generate_cache_key()Generate cache key.
- WP_Widget_Media::form()Outputs the settings update form.
- WP_Widget_Media_Audio::enqueue_admin_scripts()Loads the required media files for the media manager and scripts for media widgets.
- WP_Widget_Media_Gallery::enqueue_admin_scripts()Loads the required media files for the media manager and scripts for media widgets.
- WP_Widget_Media_Image::enqueue_admin_scripts()Loads the required media files for the media manager and scripts for media widgets.
- WP_Widget_Media_Video::enqueue_admin_scripts()Loads the required scripts and styles for the widget control.
- _wp_customize_include()Includes and instantiates the WP_Customize_Manager class.
- get_theme_starter_content()Expands a theme's starter content configuration using core-provided data.
- wp_dropdown_users()Creates dropdown HTML content of users.
- wp_get_code_editor_settings()Generates and returns code editor settings.
- wp_list_authors()Lists all the authors of the site, with several options available.
- wp_list_users()Lists all the users of the site, with several options available.
- wp_update_comment()Updates an existing comment in the database.
Source code
function wp_array_slice_assoc( $input_array, $keys ) { $slice = array(); foreach ( $keys as $key ) { if ( isset( $input_array[ $key ] ) ) { $slice[ $key ] = $input_array[ $key ]; } } return $slice;}Changelog
Introduced in 3.1.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 6.9.7 tag, from
src/wp-includes/functions.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.