Jaulush
Jaulush

Reputation: 1

Associative Array in Codeigniter

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

Answers (1)

skyyler
skyyler

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

Related Questions