Hello. I did not work with arrays at all and for me it is a dark forest, I can not understand how you can get data from this class

static function get_counts( $buckets ) { $counts = array(); $total = 0; foreach ( array( 'member', 'guest', 'bot' ) as $user_type ) { $count = isset( $buckets[$user_type] ) ? count( @$buckets[$user_type] ) : 0; $total += $counts[$user_type] = $count; } $counts['user'] = $total; return $counts; } 

For this template:

 UserOnline_Template::get_counts('member'); 

When withdrawing:

 print UserOnline_Template::get_counts( 'member' ); 

writes array, and error - Array to string conversion

Plugin: wp-useronline, from the template-tags.php file I killed a couple of evenings, got confused with this output, since I really need to get the number from this class

  • 3
    "I killed a couple of evenings already " - and it was necessary to spend only a little time on studying the primer . And it is desirable before you take on any code at all. - PinkTux
  • Yes, I read such "primers" and still can not figure out the array - Nikolay

1 answer 1

Return only one element of the array return $ counts ['user'], or in the calling program print (UserOnline_Template :: get_counts ('member') ['user'])

  • Thanks for the answer, but only zero is displayed, used both your options and changed the values ​​and no way. At least from the array at least something is displayed) - Nikolay