我从数组中提取数据,但是显示数据的某些部分高于其他数据,我设法选择某些文字高于其他数据。无论如何,如果它与我提供的文本相匹配,使用下面的代码来隐藏数组中的文本?
<?php $datas = array_slice($facilities, 0, $leftoshownumber); // First 6 items
foreach($datas as $data) {
echo '<div class="checkmark-33"><div class="fa-stack fa-1x checkmark-icon"><i class="fa fa-circle fa-stack-2x icon-background"></i><i class="fa fa-check fa-stack-1x icon-text"></i></div><div class="checkmark-inner">'. $data->Name .'</div></div>';
}; ?>
这是本节的完整代码
<div class="checkmark-outer">
<?php $startnumber = 6; $parkingnumber = 0; $gardennumber = 0; $dishwashernumber = 0; $summerrentnumber = 0; ?>
<?php if (strpos($facilitiesstring, 'Reduced Summer') !== false) { $summerrentnumber = 1; echo '<div class="checkmark-33"><div class="fa-stack fa-1x checkmark-icon"><i class="fa fa-circle fa-stack-2x icon-background"></i><i class="fa fa-check fa-stack-1x icon-text"></i></div><div class="checkmark-inner">Reduced Summer Rent Available</div></div>';}; ?>
<?php if (strpos($facilitiesstring, 'Parking') !== false) {$parkingnumber = 1; echo '<div class="checkmark-33"><div class="fa-stack fa-1x checkmark-icon"><i class="fa fa-circle fa-stack-2x icon-background"></i><i class="fa fa-check fa-stack-1x icon-text"></i></div><div class="checkmark-inner">Parking Available</div></div>';}; ?>
<?php if (strpos($facilitiesstring, 'Garden') !== false) {$gardennumber = 1; echo '<div class="checkmark-33"><div class="fa-stack fa-1x checkmark-icon"><i class="fa fa-circle fa-stack-2x icon-background"></i><i class="fa fa-check fa-stack-1x icon-text"></i></div><div class="checkmark-inner">Garden</div></div>';}; ?>
<?php if (strpos($facilitiesstring, 'Dishwasher') !== false) {$dishwashernumber = 1; echo '<div class="checkmark-33"><div class="fa-stack fa-1x checkmark-icon"><i class="fa fa-circle fa-stack-2x icon-background"></i><i class="fa fa-check fa-stack-1x icon-text"></i></div><div class="checkmark-inner">Dishwasher</div></div>';}; ?>
<?php $totalfixednumber = $parkingnumber + $gardennumber + $dishwashernumber + $summerrentnumber; $leftoshownumber = $startnumber - $totalfixednumber;?>
<?php $datas = array_slice($facilities, 0, $leftoshownumber); // First 6 items
foreach($datas as $data) {
echo '<div class="checkmark-33"><div class="fa-stack fa-1x checkmark-icon"><i class="fa fa-circle fa-stack-2x icon-background"></i><i class="fa fa-check fa-stack-1x icon-text"></i></div><div class="checkmark-inner">'. $data->Name .'</div></div>';
}; ?>
<div class="clearfix"></div>
<div class="read-more-show hide">Show More</div><div class="read-more-content"><?php $datas = array_slice($facilities, 6); // Items after 6
foreach($datas as $data) {
echo '<div class="checkmark-33"><div class="fa-stack fa-1x checkmark-icon"><i class="fa fa-circle fa-stack-2x icon-background"></i><i class="fa fa-check fa-stack-1x icon-text"></i></div><div class="checkmark-inner">'. $data->Name .'</div></div>';
}; ?><div class="clearfix"></div><div class="read-more-hide hide">Show Less</div></span></div>
</div>
任何帮助都会很棒!
答案 0 :(得分:2)
您的意思是当名称与给定变量匹配时,您不想打印整行吗? 然后我会这样做:
$iDontWant="bla"
foreach($datas as $data) {
if($data->Name == $iDontWant) continue;
echo '<div class="checkmark-33"><div class="fa-stack fa-1x checkmark-icon"><i class="fa fa-circle fa-stack-2x icon-background"></i><i class="fa fa-check fa-stack-1x icon-text"></i></div><div class="checkmark-inner">'. $data->Name .'</div></div>';
}; ?>
编辑:
如果你想要多个名字不显示你可以这样做:
$iDontWant1="bla1"
$iDontWant2="bla2"
$iDontWant3="bla3"
foreach($datas as $data) {
if($data->Name == $iDontWant1 || $data->Name == $iDontWant2 || $data->Name == $iDontWant3) continue;
echo '<div class="checkmark-33"><div class="fa-stack fa-1x checkmark-icon"><i class="fa fa-circle fa-stack-2x icon-background"></i><i class="fa fa-check fa-stack-1x icon-text"></i></div><div class="checkmark-inner">'. $data->Name .'</div></div>';
}; ?>
('||'代表'或'顺便说道)
所以基本上你正在做的是说什么时候
该名称与$iDontWant1
的内容相同,即“bla1”
或该名称与$iDontWant2
相同,即“bla2”
或该名称与$iDontWant3
的内容相同,即“bla3”
执行继续(不要打印此部分)。
然而如果你知道什么是“bla1”,“bla2”......那就更容易了
foreach($datas as $data) {
if($data->Name == "bla1" || $data->Name == "bla2" || $data->Name == "bla3") continue;
echo '<div class="checkmark-33"><div class="fa-stack fa-1x checkmark-icon"><i class="fa fa-circle fa-stack-2x icon-background"></i><i class="fa fa-check fa-stack-1x icon-text"></i></div><div class="checkmark-inner">'. $data->Name .'</div></div>';
}; ?>
您只需直接与String进行比较,而不是与包含字符串的变量进行比较。
我希望我可以帮助你。
但是如果你想用PHP做更多的事情我会推荐像https://secure.php.net/manual/en/tutorial.php这样的教程来真正理解这种语言背后的概念