简体   繁体   English

PHP:如何从键中带有连字符/破折号的关联数组中提取()值?

[英]PHP: How to extract() values from an associative array with hyphens/dashes in their keys?

I'm referring to this question .我指的是这个问题 Is it possible to extract() values from an associative array with hyphens/dashes in their keys by now ?现在是否可以从键中带有连字符/破折号的关联数组中extract()值?

It's about an older version of the WordPress Shortcode API .这是关于旧版本的WordPress 简码 API Example:例子:

function bartag_func( $atts ) {
    extract( shortcode_atts( array(
        'foo-bar' => 'something'
    ), $atts ) );

    return "foo = ${foo-bar}";
}
add_shortcode( 'bartag', 'bartag_func' );

It is still not possible .这仍然是不可能的 However, for the PHP.net engine, I have an RFC under discussion that would make it possible in PHP 8.但是,对于 PHP.net 引擎,我有一个 RFC 正在讨论中,它可以在 PHP 8 中实现。

shortcode_atts returns an array so just use it. shortcode_atts返回一个数组,所以只需使用它。

function bartag_func( $atts ) {
    $params = shortcode_atts( array(
        'foo-bar' => 'something'
    ), $atts ) );

    return "foo = " . $params['foo-bar'];
}
add_shortcode( 'bartag', 'bartag_func' );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM