0

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);
}
1
  • whats the problem you are facing? Commented Apr 18, 2016 at 12:54

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.