0

I have two array Array1 and Array2 and want to get related data from these arrays. let me elaborate further.

Array1

Array
(
    [42] => 1
)

Array2

Array
(
    [42] => 30215
    [43] => 15478
)

Now i want to something like this.

 Array
    (
        [42] => 30215
    )
4
  • Would like to see your so far efforts to achieve this. Commented Jun 5, 2015 at 6:46
  • directly use array2.. no need of array1 ? Commented Jun 5, 2015 at 6:47
  • directly i want to opposite to array_diff_key() Commented Jun 5, 2015 at 6:48
  • Since in your first array your keys are not the values you don't have to flip it and just take the: array_intersect_key() of both arrays Commented Jun 5, 2015 at 6:49

1 Answer 1

1

Here array_intersect_keys will returns an associative array containing all the entries of array1 which have keys that are present in all arguments. and max will find the highest value of those

$arr1 = Array
(
    '42' => 1
);
$arr2 = Array
(
    '42' => 30215,
    '43' => 15478
);
echo max(array_intersect_key($arr2, $arr1));//30215
Sign up to request clarification or add additional context in comments.

1 Comment

thanks dear, i was just far to add _key :D

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.