php - Limit foreach to output 4 results -
someone please help limit below foreach code output 4 results , in desc order. give thanks much!
foreach( $users_who_like $id ) : if ( $id != $user_id ) $output .= ' · <a href="' . bp_core_get_user_domain( $id ) . '" title="' . bp_core_get_user_displayname( $id ) . '">' . bp_core_get_user_displayname( $id ) . '</a>'; endforeach;
you may utilize count
, check if it's 4
$count = 4; foreach( $users_who_like $id ){ if ( $id != $user_id ) $output .= ' · <a href="' . bp_core_get_user_domain( $id ) . '" title="'.bp_core_get_user_displayname( $id ) . '">' . bp_core_get_user_displayname( $id ) .'</a>'; if(count <=0) break; //will break if statement , foreach $count--; // cut down 1 }
php foreach
No comments:
Post a Comment