wp_array_slice_assoc() - WordPress 函数参考中文文档

返回介绍

wp_array_slice_assoc()

发布于 2017-09-11 字数4006 浏览 787 评论 0

wp_array_slice_assoc( array $array,  array $keys )

Extract a slice of an array, given a list of keys.


描述


参数

$array

(array)
(Required)
The original array.

$keys

(array)
(Required)
The list of keys.


返回值

(array) The array slice.


源代码

File: wp-includes/functions.php

function wp_array_slice_assoc( $array, $keys ) {
	$slice = array();
	foreach ( $keys as $key )
		if ( isset( $array[ $key ] ) )
			$slice[ $key ] = $array[ $key ];

	return $slice;
}

更新日志

Version 描述
3.1.0 Introduced.

相关函数

Used By

  • wp-includes/widgets/class-wp-widget-media-audio.php:
    WP_Widget_Media_Audio::enqueue_admin_scripts()
  • wp-includes/widgets/class-wp-widget-media-video.php:
    WP_Widget_Media_Video::enqueue_admin_scripts()
  • wp-includes/widgets/class-wp-widget-media.php:
    WP_Widget_Media::form()
  • wp-includes/widgets/class-wp-widget-media-image.php:
    WP_Widget_Media_Image::enqueue_admin_scripts()
  • wp-includes/class-wp-customize-manager.php:
    WP_Customize_Manager::import_theme_starter_content()
  • wp-includes/theme.php:
    get_theme_starter_content()
  • wp-includes/class-wp-term-query.php:
    WP_Term_Query::get_terms()
  • wp-includes/class-wp-network-query.php:
    WP_Network_Query::get_networks()
  • wp-includes/class-wp-site-query.php:
    WP_Site_Query::get_sites()
  • wp-includes/class-wp-customize-manager.php:
    WP_Customize_Manager::set_autofocus()
  • wp-includes/class-wp-comment-query.php:
    WP_Comment_Query::get_comment_ids()
  • wp-includes/class-wp-comment-query.php:
    WP_Comment_Query::fill_descendants()
  • wp-includes/customize/class-wp-customize-nav-menu-setting.php:
    WP_Customize_Nav_Menu_Setting::sanitize()
  • wp-includes/customize/class-wp-customize-nav-menu-setting.php:
    WP_Customize_Nav_Menu_Setting::update()
  • wp-includes/customize/class-wp-customize-nav-menu-setting.php:
    WP_Customize_Nav_Menu_Setting::value()
  • wp-includes/customize/class-wp-customize-nav-menu-item-setting.php:
    WP_Customize_Nav_Menu_Item_Setting::sanitize()
  • wp-includes/class-wp-comment-query.php:
    WP_Comment_Query::get_comments()
  • wp-includes/class-wp-customize-panel.php:
    WP_Customize_Panel::json()
  • wp-includes/class-wp-customize-section.php:
    WP_Customize_Section::json()
  • wp-includes/theme.php:
    _wp_customize_include()
  • wp-includes/user.php:
    wp_dropdown_users()
  • wp-includes/post.php:
    get_pages()
  • wp-includes/author-template.php:
    wp_list_authors()
  • wp-includes/comment.php:
    wp_update_comment()
  • Show 19 more used by
    Hide more used by


User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by mrbobbybryant

    
    $options= get_option( 'my_theme' );
    
    $needed_keys = array(
       'key_1',
       'key_4',
       'key_5',
    );
    $filtered_keys = wp_array_slice_assoc( $options, $needed_keys );
    

    This will return an associative array with only the key/value pairs that you need.

上一篇:wp_allow_comment()

下一篇:wp_attachment_is()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!