3

I have an array like

$a=array([0]=>0 [1]=>3)

$b=array([0]=>image [1]=>profile [2]=>password [3]=>login)

i want to compare array a's key value i.e 0 to array b's index value 0

3 Answers 3

4

Use this

$a = array(0, 3);
$b = array(0 => 'image', 1 => 'profile', 2 => 'password', 3 => 'login');
$c = array_intersect_key($b, array_flip($a));

Results

Array
(
    [0] => image
    [3] => login
)
Sign up to request clarification or add additional context in comments.

Comments

3

Use inarray into foreach

<?php
$a = array(0,3);
$b= array('image','profile','password','login');


foreach($b as $key=>$value){
    if(in_array($key, $a)) {
        echo $value."<br>";
    }
    }
?>

Output

image
login

Comments

0

try array_intersect

array_intersect($a,$b);

or try === operator to compare the value in the array

<?php
  $a=array(0,3);
  $b=array(image,password);

 foreach($a as $k=>$v){

   if($a[$k]===$b[$k]){

     echo "$k  index is Same<br>";
   }else{

     echo "$k  index is different<br>";
   }


   }

output

0 index is different
1 index is different

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.