0

How to echo an array to a form?

My array

Array
(
    [0] => Array
        (
            [id] => item1
            [price] => 300
            [quantity] => 1
        )
    [1] => Array
        (
            [id] => item2
            [price] => 400
            [quantity] => 2
        )
)

I tried like (codeigniter):

echo form_textarea('detail_prod',print_r($detail));

And I got like

enter image description here

what happen? why the result is 1 ?

It's possible to echo to a form in array format?

4
  • You have to run through the array with a foreach loop to echo things out. Which part of the form are you trying to populate? Textarea, textfield, select? Commented Mar 29, 2016 at 4:39
  • 1
    Did you check the function parameters of form_textarea ? Commented Mar 29, 2016 at 4:42
  • @SankarV : Ya beat me to it! :-) +1 to you. :-) Try : ellislab.com/codeigniter/user-guide/helpers/form_helper.html. Commented Mar 29, 2016 at 4:44
  • what are you trying to do anyway? you want that exact pre formatted look inside a text area? Commented Mar 29, 2016 at 4:51

1 Answer 1

1

Just pass the 2nd parameter true like below:

echo form_textarea('detail_prod',print_r($detail, true));

For your help: http://php.net/manual/en/function.print-r.php

Hope this will useful.

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.