0

Controller:

function checkedServices() {

        $data = array();
        foreach($this->input->post('check_service') as $ser) {
            $data[] = array('service' => $ser);
        }

        $checked_services['services'] = array($data);

        $this->load->view('checked_services', $checked_services);
    }

view:

foreach($services as $ser)
    {   
        echo $ser;
    }

Output:

Severity: Notice

Message: Array to string conversion

Filename: views/checked_services.php

3
  • You should modify your controller. It's complicated. Commented Nov 21, 2014 at 10:20
  • you have added an array so you need to include one more foreach loop for $user in view Commented Nov 21, 2014 at 10:21
  • no need to wrap one more array this array($data); in controller, simply assign $checked_services['services'] = $data; Commented Nov 21, 2014 at 13:33

3 Answers 3

1

In Controller

function checkedServices() 
{

        $data = array();
        foreach($this->input->post('check_service') as $ser) {
            $data[]['service'] = $ser;
        }

        $checked_services['services'] = $data;

        $this->load->view('checked_services', $checked_services);
    }

In View

foreach($services as $ser)
{
  echo $ser['service'];
}
Sign up to request clarification or add additional context in comments.

1 Comment

You're Welcome. Happy to help you out.
0

$data is array

$checked_services['services'] = $data;

Comments

0

You are making a simple code complex.

Just remove array from this statement.

$checked_services['services'] = $data;

In your controller, you are looping and getting data in $data.

$data is already an array, why do you want array($data)?

4 Comments

I think he also need to change this line foreach($this->input->post('check_service') as $ser) { $data[] = array('service' => $ser); } to foreach($this->input->post('check_service') as $ser) { $data[] = $ser; }
Thanks for response.I want that user should be able to see that what services he has selected. When I use print_r(services);, all the services are printed but in an array form not normal form
If its array, loop over it using foreach. You will get the solution.
I changed $checked_services['services'] = array($data); to $checked_services['services'] = $data;.. then I used print_r($services); on view it printed all the values but in array format

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.