尝试编写一个简单的 PHP 函数,该函数接受一个数组,然后根据数组的计数吐出某些代码。在我的测试用例中,有两个用户,第一个if
发生在第二个应该有的时候。
下面是代码:
我认为问题在于这些:
if (count($users) == '1' || '3') {
if (count($users) == '2' || '4') {
但我不确定!
<?php
$template_directory = get_template_directory_uri();
$users = get_users();
if (count($users) == '1' || '3') {
foreach ($users as $user) {
if ($user->displayname != '') {
echo '<div class="col-lg-4 col-md-4 col-sm-4">';
echo '<div class="selection-member">';
echo '<div class="individual-pic">'.get_avatar($user).'</div>';
echo '<h4 class="selection-name">' .$user->displayname. '</h5>';
echo '<h5 class="grey-tagline">'.$user->jobtitle.'</h5>';
echo '<div class="selection-text quick-center">';
echo '<p>' . $user->desc . '</p>';
echo '</div> <!-- end selection-text -->';
echo '<div class="team-twitter">';
echo '<a href="http://twitter.com/'.$user->twitter.'"><svg width="36" height="36">';
echo '<image xlink:href="'.get_template_directory_uri().'/images/team-twitter.svg" src="'.get_template_directory_uri().'/images/team-twitter.png" width="36" height="36"/>';
echo '</svg></a>';
echo '</div> <!-- end team-twitter -->';
echo '</div> <!-- end selection-member -->';
echo '</div> <!-- end col-lg-4 -->';
}
}
}
elseif (count($users) == '2' || '4') {
foreach ($users as $user) {
if ($user->displayname != '') {
echo '<div class="col-lg-4 col-lg-offset-1 col-md-6 col-sm-6">';
echo '<div class="selection-member">';
echo '<div class="individual-pic">'.get_avatar($user).'</div>';
echo '<h4 class="selection-name">' .$user->displayname. '</h5>';
echo '<h5 class="grey-tagline">'.$user->jobtitle.'</h5>';
echo '<div class="selection-text quick-center">';
echo '<p>' . $user->desc . '</p>';
echo '</div> <!-- end selection-text -->';
echo '<div class="team-twitter">';
echo '<a href="http://twitter.com/'.$user->twitter.'"><svg width="36" height="36">';
echo '<image xlink:href="'.get_template_directory_uri().'/images/team-twitter.svg" src="'.get_template_directory_uri().'/images/team-twitter.png" width="36" height="36"/>';
echo '</svg></a>';
echo '</div> <!-- end team-twitter -->';
echo '</div> <!-- end selection-member -->';
echo '</div> <!-- end col-lg-4 -->';
echo '<div class="col-lg-1"></div>';
}
}
}
?>
谢谢!
编辑:非常感谢大家。我是 PHP 新手。谢谢!