首页 > 解决方案 > 在php foreach中循环一个字符串数组

问题描述

我在php中的foreach有问题。我有来自前端数据库的动态数据。但有些段落是手动的,但它应该随着 foreach 循环而改变。

$para = array
(
array("one","Get an authentic taste of the Malabar Coast as you cruise through the green Nilgiris and feast on the ancient history of the South.","Take a tour through the idyllic beaches of the Konkan Coast, while absorbing the rich culture of the majestic forts and stunning Sahyadri Hills.")
);
$i = 1;
foreach($allRides as $rides){ 
if ($i == 3) {
$i = 1;
}
$detail = $rides->_field_data['nid']['entity'];
$title = $detail->title;
$noofdays = $detail->field_tour_days['und'][0]['value'];
$noofdetails = $detail->field_more_details_of_the_tour['und'][0]['value'];
$noofdetailshort = $para[0][$i];
$image = image_style_url("homepage_ride",$detail->field_large_image['und'][0]['uri']);
$articleURL = url("node/".$rides->nid,array("absolute"=>true));
?>
<div class="places-slider-list">
<a href="<?php echo $articleURL;?>">
<img src="<?php echo $image;?>" class="img-responsive" alt="<?php echo $title;?>">
</a>
<article class="places-slider-data">
<h4><?php echo $title;?></h4>
<p><?php echo $noofdays;?> Day Guided Tour</p>
<a href="<?php echo $articleURL;?>" class="button-common-red">View Tour</a>
</article>
<div class="main-slider-sidebar">
<p><?php echo $noofdetailshort;?></p>
</div>
</div>
<?php $i++;} ?>

我想为每个循环放置这个数组数据意味着它是一个具有不同价格标题的滑块,我想静态添加这些参数,但我不知道该怎么做。

标签: phpforeachdrupal

解决方案


推荐阅读