phpcodeigniterphp-shorttags

Variable declaration wrapped in <?= ... ?> is printing unwanted word "Array"


I was following code igniter user guide for forms and I encountered this strange output can anyone tell how to fix it?

Here is my code for beginning of the form

<?= $attributes = array('class' => 'email', 'id' => 'myform'); ?>
<?= form_open('email/index/', $attributes); ?>

I get form with id and class which I specified above but for some reason 1Array1 text prints out and I can't figure out why.


Solution

  • Try

    <? $attributes = array('class' => 'email', 'id' => 'myform');?>
    <?=form_open('email/index/', $attributes); ?>
    

    The <?= ?> is a shortcut to <?php echo ... ?>, so your $attributes array would not only be created, but also printed.

    The <? ?> is a shortcut for <?php ?> so that should fix it.