Count arrays comma separated values

后端 未结 3 815
迷失自我
迷失自我 2021-01-25 01:40

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         


        
相关标签:
3条回答
  • 2021-01-25 02:33

    Please try code given below

    if( !empty( $my_var ) ) {
        $meta_counts = array();
        $total_count = 0;  
        foreach( $my_var as $meta_index=>$meta_value ){
             if(isset($meta_index) && !empty($meta_index)){
                $meta_index_arr = explode(',', $meta_index);
                $meta_counts[$meta_index] = count($meta_index_arr);   
                $total_count += $meta_counts[$meta_index];
             }else{
                              $meta_counts[$meta_index] = 0;
            }
         }
    
    }
    print_r ($meta_counts);
    echo $total_count;
    

    thanks

    0 讨论(0)
  • 2021-01-25 02:36

    you can get 13 words or phrases by this

    $words = array_map('trim', explode(',', implode(',', array_keys($meta_counts))));
    
    0 讨论(0)
  • 2021-01-25 02:37

    There is a function called explode that lets you split the array.

    Here is the link for it.

    This should probably do some need.

    http://php.net/manual/en/function.explode.php

    0 讨论(0)
提交回复
热议问题