codeigniter-Creating loops

Creating loops in view files has been a stumbling block for a few developers. By
passing a multidimensional array to a view file, you can easily establish a loop in
any of your view files. Let's take a look at an example.
<?php
class Todo extends Controller
{
function index()
{
$data['todo_list'] = array("buy food", "clean up", "mow lawn");
$this->load->view('todo', $data);
}
}
?>
This is a very simple Controller. Your view file for this would be as follows:
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<h1><?php echo $heading; ?></h1>
<?php echo $content;?>
<h2>My Todo List</h2>
<?php
foreach($todo_list as $item)
{
echo $item;
}
?>
</body>
</html>

Returning views as data
Youare also able to return view files as data; this can be useful if you wish to process
this data in some way. Simply set the third parameter to boolean TRUE—and it will
return the view data.

$this->load->view('welcome', NULL, TRUE);

CodeIgniter uses an output buffer to take all calls to the load view function, and
processes them all at once, sending the whole page to the browser at the same time.
So when you return views as data, you will be able to save the contents of theview
inside a variable for whatever use you need.