English 中文(简体)
Echo an Array Key. How?
原标题:Echo an Array Key.. how?

期望与我的阵列的价值一致,这对这位控制者的看法至关重要。 我很想知道。 因此,就第一点点而言,我要对这一观点表示赞同。 然后,它会穿透其余部分。

这里是我的控制员守则:

function index()
{
$this->load->library( simplepie );
       $feeds = array( mmafighting  =>  http://www.mmafighting.com/rss/current ,
                     bbc  =>  http://feeds.bbci.co.uk/news/world/us_and_canada/rss.xml ,
                     bloodyelbow  =>  http://www.bloodyelbow.com/rss ,
                     ufc  =>  http://www.ufc.com/rss/news ,
                     hackernews  =>  http://news.ycombinator.com/rss ,
                     msnbc  =>  http://www.msn.com/rss/news.aspx ,
                     msnbc2  =>  http://www.msn.com/rss/msnmoney.aspx ,
                     msnbc3  =>  http://www.msn.com/rss/msnshopping_top.aspx 

                 );
    foreach ($feeds as $site=>$url)
    {
        $data[ feed ][$site] = new SimplePie();
        $data[ feed ][$site]->set_feed_url($url);
        $data[ feed ][$site]->set_cache_location(APPPATH. cache );
        $data[ feed ][$site]->set_cache_duration(300);
        $data[ feed ][$site]->init();
        $data[ feed ][$site]->handle_content_type();
    }
    $this->load->view( feedsview , $data);
}

这里我的看法是:

<?php
$feedCount = 0; 
$rowCount = 0;
?>
<?php foreach ($feed as $site): ?>

    <?php if ($site->data): ?>
            <div class="feed">
            <h2><?php // echo original array key here ?></h2>
            <ul>
            <?php $items = $site->get_items(0, 5); ?>
            <?php foreach ($items as $item): ?>
                <li><a href="<?php echo $item->get_link(); ?>"><?php echo $item->get_title(); ?></a></li>
            <?php endforeach; ?>
        </ul>
        </div>
        <?php endif; ?>



<?php $feedCount++; ?>
<?php if ($feedCount === 3) {
    echo  <div style="clear:both;">&nbsp;</div> ;
    $feedCount = 0;
    $rowCount++;
        if ($rowCount === 2) {
            echo  <div style="width:1000px; margin-bottom:20px;height:100px; border:1px solid #252525; float:left;">images</div> ;
            }
    } ?>
    <?php endforeach; ?>
最佳回答

我不敢理解,而是要理解:

<?php foreach ($feed as $key => $site): ?>

    <?php if ($site->data): ?>
            <div class="feed">
            <h2><?php echo $key ?></h2>
            <ul>
问题回答

暂无回答




相关问题
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 ...

热门标签