伯爵逗号分隔值数组 [英] Count arrays comma separated values

查看:116
本文介绍了伯爵逗号分隔值数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个函数来获取自定义元字段在Word preSS数组

I'm using this function to get an array of custom meta fields in 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);

该阵列它生成的样子

The array it generates looks like

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

How can I get a total count of each word or phrase that's separated by a comma. Not each individual word. In the array above the count would be 13

感谢

推荐答案

您可以得到的 13 这个词或短语

you can get 13 words or phrases by this

$words = array_map('trim', explode(',', implode(',', array_keys($meta_counts))));

这篇关于伯爵逗号分隔值数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆