Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7861153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:35:02+00:00 2026-06-02T22:35:02+00:00

Im looking to echo the value of my array key out into the view

  • 0

Im looking to echo the value of my array key out into the view for this controller. I cant quite figure it out. So for the first feed I want to echo mmafighting into the of the view. Then it would loop through the rest.

Here is my controller code:

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);
}

Here is my view code:

<?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; ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:35:07+00:00Added an answer on June 2, 2026 at 10:35 pm

    I’m not sure i understand but what about doing this :

    <?php foreach ($feed as $key => $site): ?>
    
        <?php if ($site->data): ?>
                <div class="feed">
                <h2><?php echo $key ?></h2>
                <ul>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this function to search the (highest) array key when a value of
I have this combination of multi-dimensional array but I can't print the correct value
I'm looking for the quickest/shortest way to get the first value from comma separated
I have posted this a few times looking for some help, I cant seem
I'm looking for a elaborate list comparing different operations in PHP. For example: echo
Looking back at my past projects I often encounter this one: A client or
I am using this ViewScript for my standard form elements: <div class=field id=field_<?php echo
I have this simple function which I pass in an array of strings: function
This is assignment so not looking for anything perfectly safe and secure, just working.I
i was wondering if this setup would work. i have to crank out a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.