Count arrays comma separated values

后端 未结 3 850
迷失自我
迷失自我 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

提交回复
热议问题