Bird
0
0

Given two arrays $a = [1, 2, 3]; and $b = [3, 4, 5];, which function returns an array of values present in both arrays?

hard📝 Application Q9 of 15
PHP - Array Functions
Given two arrays $a = [1, 2, 3]; and $b = [3, 4, 5];, which function returns an array of values present in both arrays?
Aarray_diff()
Barray_intersect()
Carray_merge()
Darray_unique()
Step-by-Step Solution
Solution:
  1. Step 1: Understand the goal

    We want values common to both arrays.
  2. Step 2: Identify the correct function

    array_intersect() returns elements found in all arrays passed.
  3. Final Answer:

    array_intersect() -> Option B
  4. Quick Check:

    Common elements = array_intersect() [OK]
Quick Trick: Use array_intersect() to find common values [OK]
Common Mistakes:
  • Using array_merge() which combines arrays
  • Using array_diff() which finds differences

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes