我正在使用此函数在 WordPress 中获取一组自定义元字段
$my_var = get_meta_values( 'keywords' );
if( !empty( $my_var ) ) {
$meta_counts = array();
foreach( $my_var as $meta_value )
$meta_counts[$meta_value] = ( isset( $meta_counts[$meta_value] ) ) ? $meta_counts[$meta_value] + 1 : 1;
}
print_r ($meta_counts);
它生成的数组看起来像
Array (
[one, two, three, four and five, six and seven] => 1
[clean, ajax one, two three, four five] => 1
[] => 1
[this is a test, working] => 1
[asdfasdf] => 1
[last test] => 1
)
如何获得以逗号分隔的每个单词或短语的总数。不是每个单词。在上面的数组中,计数为 13
谢谢