返回介绍

wp_array_slice_assoc()

发布于 2017-09-11 11:33:34 字数 4004 浏览 873 评论 0 收藏 0

wp_array_slice_assoc( array $array,  array $keys )

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


description


参数

$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;
}

更新日志

Versiondescription
3.1.0Introduced.

相关函数

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文