Reputation: 1
How can I show an associative array in codeigniter view from controller page? Here is my code below. I want to show the values of array in view. Please help me!
function colorr(){
$color['color'] = array("RED"=>"#FFCC00","GREEN"=>"#99FF00","YELLOW"=>"#FF0000");
$this->load->view('color_all',$color);
}
Upvotes: 0
Views: 822
Reputation: 165
In your view file, you can access it by:
print $color["RED"]; // will output "#FFCC00"
print $color["GREEN"]; // will output "#99FF00"
Or you can loop:
foreach($color as $k => $v)
{
print $k . " => " . $v . " <br />";
}
In your case, this will output something like this:
RED => #FFCC00
GREEN => #99FF00
YELLOW => #FF0000
Upvotes: 1