<?php
$val=array(4,10,15);
$val2=array('ravi,suresh,kumar');
foreach ($val2 as $title) {
foreach ($val as $title1) {
echo $title;
echo $title1;
}
}
?>
o/p: ravi,suresh,kumar4ravi,suresh,kumar10ravi,suresh,kumar15
but i requeied ravi 4 suresh10 kumar15
Use one loop.
for($i = 0; $i < count($val); $i++) {
print $val[$i] . " " . $val2[$i];
}
The issue with your nested for loops is that it iterates over the first element of val1, then all the elements of val 2. Then the 2nd element of val1, and all the elements of val2 and so on.
since you want to go through both at the same time, use a standard for loop.