Search code examples
phparraysfor-loopforeachimplode

how to display array foreach php


i'm newbie in php foreach. Here's my code:

$name= array("1", "2", "3");
$say= array("one", "two", "three");
foreach ($name as $v) {
$nm= $v;
$show = array();
    foreach($say as $value) 
    $show[] = $nm.'='.$value;
    $show = implode("<br>",$show);
}

How can i display something like this

1=one
2=two
3=three

Solution

  • Make use of a for loop instead.

    $name= array("1", "2", "3");
    $say= array("one", "two", "three");
    
    for($i=0;$i<count($name);$i++)
    {
    echo "$name[$i]=$say[$i]<br>";
    }
    

    Demo