[英]How to select the end of a dynamically-generated array and hide part of its content?
每個人!
我的網站有一個通過 PHP 動態生成的辦公室聯系人列表(下面的部分片段)。 如您所見,每個列表結果/子項都有一個名稱、地址,並且在接下來的 div 上有一個 google 地圖框架。 我想要實現的是調用數組的最新結果,並使該結果不顯示谷歌地圖 div。
我想我可以用“end()”命令調用它,但我無法以正確的方式繼續前進……有人能指出我正確的方向嗎?
謝謝!
<header id="standardheader">
<div class="wrap">
<nav class="standardsubnav">
<ul class="standardsubnav_list vanilla"><!--
<?php include_partial( 'contact/citynav', array('class' => 'standardsubnav') ); ?>
--></ul>
</nav>
<h1 class="standardpage_title"><?php echo $current->getHeadline(); ?></h1>
</div>
</header>
<div class="wrap">
<section class="">
<ul class="list4 vanilla">
<?php $contacts = $current->getChildren(); ?>
<?php foreach($contacts as $contact): $settings = $contact->getSettings(); ?>
<li class="item4">
<a name="<?php echo $settings['city']; ?>"></a>
<div class="link4">
<div class="link4_inner">
<h2 class="title4"><?php echo $settings['city']; ?></h2><!--
--><address class="address4">
<?php echo $settings['name']; ?><br />
<?php if(isset($settings['address1']) && $settings['address1'] != "") echo $settings['address1'] . '<br />'; ?>
<?php if(isset($settings['address2']) && $settings['address2'] != "") echo $settings['address2'] . '<br />'; ?>
<?php if(isset($settings['address3']) && $settings['address3'] != "") echo $settings['address3'] . '<br />'; ?>
<?php if(isset($settings['address4']) && $settings['address4'] != "") echo $settings['address4'] . '<br />'; ?>
<?php if(isset($settings['phone']) && $settings['phone'] != ""): ?><a href="tel:<?php echo str_replace(' ', '', $settings['phone']); ?>">t. <?php echo $settings['phone']; ?></a><br /><?php endif; ?>
<?php if(isset($settings['fax']) && $settings['fax'] != ""): ?><a href="tel:<?php echo str_replace(' ', '', $settings['fax']); ?>">f. <?php echo $settings['fax']; ?></a><br /><?php endif; ?>
<?php if(isset($settings['email']) && $settings['email'] != ""): ?><a href="mailto:<?php echo $settings['email']; ?>">e. <?php echo $settings['email']; ?></a><?php endif; ?>
</address>
</div><!--
--><div class="link4_inner">
<?php
$mapurl = (!empty($settings['mapurl'])) ? $settings['mapurl'] : 'https://www.google.com/maps/@' . $settings['latitude'] . ',' . $settings['longitude'] . ',' . $settings['zoom'] . 'z'; ?>
<div class="gmap4" data-gmap="<?php echo htmlspecialchars( '{"lat":"'.$settings['latitude'].'","lng":"'.$settings['longitude'].'", "zoom":"'.$settings['zoom'].'", "mapurl":"'.$mapurl.'"}' ); ?>">
<noscript><?php echo __('Please enable javascript to see the map.'); ?></noscript>
<?php end($contacts)
計算 $contacts 數組。 然后在 foreach 循環中檢查當前循環中的元素是否等於數組中的項,如果等於項,則為最后一個元素,然后退出 foreach:
$items = count($contacts );
$i = 0;
foreach($contacts as $contact) {
if(++$i === $items ) {
continue;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.