-1

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

3

4 Answers 4

0

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

Sign up to request clarification or add additional context in comments.

Comments

0

var a = [ 'x' ,'y' , 'z'];
b = [ 'p', 'q', 'r']
 var newArray = a.map(function(val,index){return [val,b[index]]});
 console.log(newArray)

Comments

0

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]]}));

Comments

0

const daysNums = [1, 2, 3, 4, 5, 6, 7];
const daysNames = [
  "monday",
  "tuesday",
  "wednesday",
  "thursday",
  "friday",
  "saturday",
  "sunday"
];

daysNums.map((num, index) => {
  const f = [num, daysNames[index]];
  console.log(f);
});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.