PHP:如何从键为 hyphens/dashes 的关联数组中提取 () 值?

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

我指的是 this question。是否可以 extract() 键中带有 hyphens/dashes 的关联数组中的值 by now?

这是关于 WordPress Shortcode API 的旧版本。示例:

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 这将使 PHP 8.

成为可能

shortcode_atts returns 一个数组,所以就用它吧。

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

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