Print respective index value from two arrays in " Javascript " and in "PHP"
var a = [ x , y , z]
var b = [ p, q, r]
then => values [x, p] , [ y, q]
please help me, Thanks you
Print respective index value from two arrays in " Javascript " and in "PHP"
var a = [ x , y , z]
var b = [ p, q, r]
then => values [x, p] , [ y, q]
please help me, Thanks you
or just straight forward:
x=[ "x" , "y" , "z"];
y=[ "p" , "q" , "r"];
for (var i = 0; i < x.length; ++i) {
alert('value at index [' + i + '] is: [' + x[i] + '] and [' + y[i] + ']');
}
as per comment in PHP:
$x= array("x" , "y" , "z");
$y= array("p" , "q" , "r");
for ($i = 0; $i < count($x); ++$i) {
echo $x[$i];
echo $y[$i];
}
also check this excellent answer here
You can use Array.prototypr.map. See below code
In php it should be like this.
$a=array("x","y","z");
$b=array("p","q","r");
$c=array_map(null,$a,$b);
print_r($c);
x=[ "x" , "y" , "z"];
y=[ "p" , "q", "r"];
console.log(x.map((x1,i)=>{return [x1,y[i]]}));