How to display 2 arrays in a foreach?

Asked

Viewed 44 times

0

$array1 = ['Hello', 'World'];
$array2 = ['Hello Girl', 'Hello Boy'];

foreach($array1 as $text) 
{ 
  echo $text;]
}
  • 1

    It depends a lot on the case, it goes from having 2 foreach or until it fits in the situation a for/foreach and an Indice to control the items.

1 answer

1


<?php


$array = ['Hello', 'World'];
$array2 = ['Hello Girl', 'Hello Boy'];

foreach($array as $indice => $text) 
{ 
  echo $text;
  echo $array2[$indice];
}


?>

This way will be printed the $array and then the $array2

  • Thanks Vinicius De Jesus, but what if I wanted to do with a form using 2 inputs ? I will edit the question by putting inputs.

Browser other questions tagged

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