English 中文(简体)
Php数组chunk:第一个chunk的回声不同
原标题:Php Array chunk: echo something different for first chunk
  • 时间:2012-04-13 12:22:36
  •  标签:
  • php
  • arrays

I am using array_chunk but i want to be able to echo something different for the first array in the chunk. Not sure on how to do this and could not find anything. Any help/guidance would be appreciated.

假设我使用:

     foreach (array_chunk($entries, 4) as $row) { 

    if (the array chunk is the first) {回响<div class="cn_page" style="display:block;"> ;}
    else {回响<div class="cn_page"> ;} 

}

完整代码如下:

回响

<div id="cn_preview" class="cn_preview"> ;

foreach($entries as $entry){
回响<div class="cn_content" style="top:5px;">
      <img src="newsslider/images/polaroidphotobar.jpg" alt=""/>
      <h1> .$entry->title. </h1>
      <span class="cn_date"> .$entry->modified. </span>
      <span class="cn_category"></span>
      <p> .$entry->text. </p>
      <a href="" target="_blank" class="cn_more">Read more</a>
      </div> ;     
}
回响</div> ;


回响<div id="cn_list" class="cn_list"> ;

foreach (array_chunk($entries, 4) as $row) { 

if (the array chunk is the first) {回响<div class="cn_page" style="display:block;"> ;}
else {回响<div class="cn_page"> ;}

foreach ($row as $entry) {
$i++;

if ($i == 1){回响<div class="cn_item selected"> ;}
else {回响<div class="cn_item"> ;}

回响<h2> .$entry->title. </h2>
<p> .$entry->text. </p>
</div> ;
回响</div> ; 

}
回响</div> ; 
}
echo <div class="cn_nav">
            <a id="cn_prev" class="cn_prev disabled"></a>
            <a id="cn_next" class="cn_next"></a>
</div>
</div>
</div> ;
最佳回答

那将是:

foreach (array_chunk($entries, 4) as $key => $row) { 
    if ($key == 0) {
        echo  <div class="cn_page" style="display:block;"> ;
    } else {
        echo  <div class="cn_page"> ;
    } 
}
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签