Skip to main content
Code Review

Return to Question

replaced http://meta.codereview.stackexchange.com/ with https://codereview.meta.stackexchange.com/
Source Link

This code mimics the "likes" tooltip from Facebook.

Given an array with the list of users that liked the content, it shows the first n users and displays a final item with the count of the users not shown.

It works as expected, but I'm sure it could be better written.

<? if ($count = $this->likes->count()) { 
 $visible = 12;
 $hidden = $count > $visible ? $count - $visible : 0;
?>
 <div class="likes_detail">
<? $r = 0;
 foreach ($this->likes as $like) {
?>
 <span><?= $like->name ?></span>
<? $r++;
 if ($r >= $visible) { break; };
 }
 if ($count > $visible) { 
?>
 <span class="more_users">and <?= $hidden ?> more&hellip;</span>
<? } ?>
 </div>
<? } ?>

Edit: Removed revised code after reading this meta post this meta post.

This code mimics the "likes" tooltip from Facebook.

Given an array with the list of users that liked the content, it shows the first n users and displays a final item with the count of the users not shown.

It works as expected, but I'm sure it could be better written.

<? if ($count = $this->likes->count()) { 
 $visible = 12;
 $hidden = $count > $visible ? $count - $visible : 0;
?>
 <div class="likes_detail">
<? $r = 0;
 foreach ($this->likes as $like) {
?>
 <span><?= $like->name ?></span>
<? $r++;
 if ($r >= $visible) { break; };
 }
 if ($count > $visible) { 
?>
 <span class="more_users">and <?= $hidden ?> more&hellip;</span>
<? } ?>
 </div>
<? } ?>

Edit: Removed revised code after reading this meta post.

This code mimics the "likes" tooltip from Facebook.

Given an array with the list of users that liked the content, it shows the first n users and displays a final item with the count of the users not shown.

It works as expected, but I'm sure it could be better written.

<? if ($count = $this->likes->count()) { 
 $visible = 12;
 $hidden = $count > $visible ? $count - $visible : 0;
?>
 <div class="likes_detail">
<? $r = 0;
 foreach ($this->likes as $like) {
?>
 <span><?= $like->name ?></span>
<? $r++;
 if ($r >= $visible) { break; };
 }
 if ($count > $visible) { 
?>
 <span class="more_users">and <?= $hidden ?> more&hellip;</span>
<? } ?>
 </div>
<? } ?>

Edit: Removed revised code after reading this meta post.

Removed revised code after reading http://meta.codereview.stackexchange.com/questions/1763/for-an-iterative-review-is-it-okay-to-edit-my-own-question-to-include-revised-c/1765#1765
Source Link
Lando
  • 121
  • 4

This code mimics the "likes" tooltip from Facebook.

Given an array with the list of users that liked the content, it shows the first n users and displays a final item with the count of the users not shown.

It works as expected, but I'm sure it could be better written.

<? if ($count = $this->likes->count()) { 
 $visible = 12;
 $hidden = $count > $visible ? $count - $visible : 0;
?>
 <div class="likes_detail">
<? $r = 0;
 foreach ($this->likes as $like) {
?>
 <span><?= $like->name ?></span>
<? $r++;
 if ($r >= $visible) { break; };
 }
 if ($count > $visible) { 
?>
 <span class="more_users">and <?= $hidden ?> more&hellip;</span>
<? } ?>
 </div>
<? } ?>

Edit:

As Brythan said, there was no need for Removed revised code after reading $hiddenthis meta post.

<? if ($count = $this->likes->count()) { 
 $visible = 12;
?>
 <div class="likes_detail">
<? $r = 0;
 foreach ($this->likes as $like) {
?>
 <span><?= $like->name ?></span>
<? $r++;
 if ($r >= $visible) { break; }
 }
 if ($count > $visible) { 
?>
 <span class="more_users">and <?= $count - $visible ?> more&hellip;</span>
<? } ?>
 </div>
<? } ?>

This code mimics the "likes" tooltip from Facebook.

Given an array with the list of users that liked the content, it shows the first n users and displays a final item with the count of the users not shown.

It works as expected, but I'm sure it could be better written.

<? if ($count = $this->likes->count()) { 
 $visible = 12;
 $hidden = $count > $visible ? $count - $visible : 0;
?>
 <div class="likes_detail">
<? $r = 0;
 foreach ($this->likes as $like) {
?>
 <span><?= $like->name ?></span>
<? $r++;
 if ($r >= $visible) { break; };
 }
 if ($count > $visible) { 
?>
 <span class="more_users">and <?= $hidden ?> more&hellip;</span>
<? } ?>
 </div>
<? } ?>

Edit:

As Brythan said, there was no need for $hidden.

<? if ($count = $this->likes->count()) { 
 $visible = 12;
?>
 <div class="likes_detail">
<? $r = 0;
 foreach ($this->likes as $like) {
?>
 <span><?= $like->name ?></span>
<? $r++;
 if ($r >= $visible) { break; }
 }
 if ($count > $visible) { 
?>
 <span class="more_users">and <?= $count - $visible ?> more&hellip;</span>
<? } ?>
 </div>
<? } ?>

This code mimics the "likes" tooltip from Facebook.

Given an array with the list of users that liked the content, it shows the first n users and displays a final item with the count of the users not shown.

It works as expected, but I'm sure it could be better written.

<? if ($count = $this->likes->count()) { 
 $visible = 12;
 $hidden = $count > $visible ? $count - $visible : 0;
?>
 <div class="likes_detail">
<? $r = 0;
 foreach ($this->likes as $like) {
?>
 <span><?= $like->name ?></span>
<? $r++;
 if ($r >= $visible) { break; };
 }
 if ($count > $visible) { 
?>
 <span class="more_users">and <?= $hidden ?> more&hellip;</span>
<? } ?>
 </div>
<? } ?>

Edit: Removed revised code after reading this meta post.

added 464 characters in body
Source Link
Lando
  • 121
  • 4

This code mimics the "likes" tooltip from Facebook.

Given an array with the list of users that liked the content, it shows the first n users and displays a final item with the count of the users not shown.

It works as expected, but I'm sure it could be better written.

<? if ($count = $this->likes->count()) { 
 $visible = 12;
 $hidden = $count > $visible ? $count - $visible : 0;
?>
 <div class="likes_detail">
<? $r = 0;
 foreach ($this->likes as $like) {
?>
 <span><?= $like->name ?></span>
<? $r++;
 if ($r >= $visible) { break; };
 }
 if ($count > $visible) { 
?>
 <span class="more_users">and <?= $hidden ?> more&hellip;</span>
<? } ?>
 </div>
<? } ?>

Edit:

As Brythan said, there was no need for $hidden.

<? if ($count = $this->likes->count()) { 
 $visible = 12;
?>
 <div class="likes_detail">
<? $r = 0;
 foreach ($this->likes as $like) {
?>
 <span><?= $like->name ?></span>
<? $r++;
 if ($r >= $visible) { break; }
 }
 if ($count > $visible) { 
?>
 <span class="more_users">and <?= $count - $visible ?> more&hellip;</span>
<? } ?>
 </div>
<? } ?>

This code mimics the "likes" tooltip from Facebook.

Given an array with the list of users that liked the content, it shows the first n users and displays a final item with the count of the users not shown.

It works as expected, but I'm sure it could be better written.

<? if ($count = $this->likes->count()) { 
 $visible = 12;
 $hidden = $count > $visible ? $count - $visible : 0;
?>
 <div class="likes_detail">
<? $r = 0;
 foreach ($this->likes as $like) {
?>
 <span><?= $like->name ?></span>
<? $r++;
 if ($r >= $visible) { break; };
 }
 if ($count > $visible) { 
?>
 <span class="more_users">and <?= $hidden ?> more&hellip;</span>
<? } ?>
 </div>
<? } ?>

This code mimics the "likes" tooltip from Facebook.

Given an array with the list of users that liked the content, it shows the first n users and displays a final item with the count of the users not shown.

It works as expected, but I'm sure it could be better written.

<? if ($count = $this->likes->count()) { 
 $visible = 12;
 $hidden = $count > $visible ? $count - $visible : 0;
?>
 <div class="likes_detail">
<? $r = 0;
 foreach ($this->likes as $like) {
?>
 <span><?= $like->name ?></span>
<? $r++;
 if ($r >= $visible) { break; };
 }
 if ($count > $visible) { 
?>
 <span class="more_users">and <?= $hidden ?> more&hellip;</span>
<? } ?>
 </div>
<? } ?>

Edit:

As Brythan said, there was no need for $hidden.

<? if ($count = $this->likes->count()) { 
 $visible = 12;
?>
 <div class="likes_detail">
<? $r = 0;
 foreach ($this->likes as $like) {
?>
 <span><?= $like->name ?></span>
<? $r++;
 if ($r >= $visible) { break; }
 }
 if ($count > $visible) { 
?>
 <span class="more_users">and <?= $count - $visible ?> more&hellip;</span>
<? } ?>
 </div>
<? } ?>
edited body
Source Link
Lando
  • 121
  • 4
Loading
edited body
Source Link
Lando
  • 121
  • 4
Loading
Source Link
Lando
  • 121
  • 4
Loading
lang-php

AltStyle によって変換されたページ (->オリジナル) /