Returns value of an array dynamically

Asked

Viewed 28 times

1

I have an array

$teste = [1,2,3,4];

<Input type="text" value ="teste[0]" />

//retorna "1"

How I could bring all array values into inputs?

  • 4

    Try to explain better what you need and what you’ve tried. It’s unclear exactly what your question is.

  • @fernandosavio things start to make more sense when the question is well formatted

1 answer

2


Loop your array by adding a input for each item:

<?php
  $teste = [1,2,3,4];

  foreach ($teste as $t) {
    echo "<input type='text' value='$t'>";
  }
?>

ideone

Browser other questions tagged

You are not signed in. Login or sign up in order to post.