1

Sorry guys this is probably quite simple but I've got really stuck... I have an array - $forms which using var_dump looks like this:

array (size=1)
  'forms' => 
    array (size=3)
      0 => 
        array (size=2)
          'form_id' => string '3' (length=1)
          'form_name' => string 'another_form_to_test' (length=20)
      1 => 
        array (size=2)
          'form_id' => string '1' (length=1)
          'form_name' => string 'contact_name_changed' (length=20)
      2 => 
        array (size=2)
          'form_id' => string '2' (length=1)
          'form_name' => string 'test_form' (length=9)

I am using codeigniter and want to simply echo a value from this array, such as the third 'form_name' - I've tried lots of different things but nothing works... I thought it would be:

echo $forms['2']['form_name'];

3 Answers 3

1

try

 echo $forms['forms'][2]['form_name'];
Sign up to request clarification or add additional context in comments.

3 Comments

downvoters please check and let me know what i missing?
I did not downvote.. But the key is should not be a string. Strange that the upvoted answer is identical.. Edit the key to a int for a upvote.
No idea other then the index being a string, could you edit it to echo $forms['forms'][2]['form_name'];
1

you can try this one

<?php 
foreach($forms['forms'] as $form)
{
    echo $form['form_name'];
}
?>

Comments

1

You are missing the first level of array

echo $forms['forms'][2]['form_name'];

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.