How to get common values from 4 multidimensional arrays using array_intersect

chetan patel

i am stuck at this stage of my project.

i am trying to get common values from four multidimensional arrays using array_intersect. can anyone help me with this issue ?

here are all four array:

$arr=array(array(8159),array(8140),array(8134),array( 8168),array(8178),array( 8182),array( 8183));


$arr1=array(array(8159),array(8140),array(8134),array(8165),array(8166),array(8167),array( 8168));


$arr2=array(array(566),array(265),array(8134),array(655),array(8166),array(665),array( 8168),array(656),array( 989),array( 989));

$arr3=array(array(8159),array(8140),array(8134),array(8165),array(8166),array(8167),array( 8168));

$res= array_intersect($arr,$arr1,$arr2,$arr3); 

print_r($res);
sectus

If subarray contain one element always you could chage that value using array_map and current function.

$arr=array(array(8159),array(8140),array(8134),array( 8168),array(8178),array( 8182),array( 8183));
$arr1=array(array(8159),array(8140),array(8134),array(8165),array(8166),array(8167),array( 8168));
$arr2=array(array(566),array(265),array(8134),array(655),array(8166),array(665),array( 8168),array(656),array( 989),array( 989));
$arr3=array(array(8159),array(8140),array(8134),array(8165),array(8166),array(8167),array( 8168));

$arr = array_map('current', $arr);   // getting first value of subarray
$arr1 = array_map('current', $arr1);
$arr2 = array_map('current', $arr2);
$arr3 = array_map('current', $arr3);
print_r($arr3);
// Array
// (
//     [0] => 8159
//     [1] => 8140
//     [2] => 8134
//     [3] => 8165
//     [4] => 8166
//     [5] => 8167
//     [6] => 8168
// )

$res= array_intersect($arr,$arr1,$arr2,$arr3);
print_r($res);
// Array
// (
//    [2] => 8134
//    [3] => 8168
// )

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to get the combination of array values from nested arrays in an array of objects

分類Dev

How to distribute mysql result set in an multidimensional array of 4 arrays

分類Dev

Find Common most values in multidimensional array in PHP

分類Dev

How to turn a single array into a multidimensional array using the values?

分類Dev

How to search data in multidimensional array using range values

分類Dev

Get values from array and using the values in a program

分類Dev

PHP - Get all values with specific array key from multidimensional array with unknown depth

分類Dev

how to do Multidimensional Arrays

分類Dev

PHP - search for key in multidimensional array and get its values deeper from the structure

分類Dev

Retrieving data from multidimensional array from arrays.xml

分類Dev

get multidimensional array value using flat array

分類Dev

PHP - How to remove duplicate values from array (compare 2 arrays)

分類Dev

How to count all values in a multidimensional array?

分類Dev

Selecting random arrays from multidimensional numpy array with replacement

分類Dev

PHP - How to get the sum of a multidimensional array?

分類Dev

Get count from Array of arrays

分類Dev

How to get values from all the columns of the table in Spotfire using IronPython

分類Dev

how to get values from xml file then print them using php

分類Dev

How do I return 2 values from two arrays when using filter

分類Dev

how to print data stored in multidimensional array and fetched from database using PHP?

分類Dev

How to Get a Value from Firebase Using Ionic 4

分類Dev

Built-in method to get flat array from a multidimensional array in PHP

分類Dev

How to get an array with true/false values after comparing 2 arrays in ruby?

分類Dev

get_posts using a multidimensional array and 2 meta keys

分類Dev

How to get arrays on output from MongoDB aggregate

分類Dev

Multidimensional, get info from parent searching the child array

分類Dev

How to get distinct values from an array of fetch API output

分類Dev

How to get distinct values from an array in mongoDB and group them by ID

分類Dev

How to get the values of a column from a table in jQuery into a multidimentional array

Related 関連記事

  1. 1

    How to get the combination of array values from nested arrays in an array of objects

  2. 2

    How to distribute mysql result set in an multidimensional array of 4 arrays

  3. 3

    Find Common most values in multidimensional array in PHP

  4. 4

    How to turn a single array into a multidimensional array using the values?

  5. 5

    How to search data in multidimensional array using range values

  6. 6

    Get values from array and using the values in a program

  7. 7

    PHP - Get all values with specific array key from multidimensional array with unknown depth

  8. 8

    how to do Multidimensional Arrays

  9. 9

    PHP - search for key in multidimensional array and get its values deeper from the structure

  10. 10

    Retrieving data from multidimensional array from arrays.xml

  11. 11

    get multidimensional array value using flat array

  12. 12

    PHP - How to remove duplicate values from array (compare 2 arrays)

  13. 13

    How to count all values in a multidimensional array?

  14. 14

    Selecting random arrays from multidimensional numpy array with replacement

  15. 15

    PHP - How to get the sum of a multidimensional array?

  16. 16

    Get count from Array of arrays

  17. 17

    How to get values from all the columns of the table in Spotfire using IronPython

  18. 18

    how to get values from xml file then print them using php

  19. 19

    How do I return 2 values from two arrays when using filter

  20. 20

    how to print data stored in multidimensional array and fetched from database using PHP?

  21. 21

    How to Get a Value from Firebase Using Ionic 4

  22. 22

    Built-in method to get flat array from a multidimensional array in PHP

  23. 23

    How to get an array with true/false values after comparing 2 arrays in ruby?

  24. 24

    get_posts using a multidimensional array and 2 meta keys

  25. 25

    How to get arrays on output from MongoDB aggregate

  26. 26

    Multidimensional, get info from parent searching the child array

  27. 27

    How to get distinct values from an array of fetch API output

  28. 28

    How to get distinct values from an array in mongoDB and group them by ID

  29. 29

    How to get the values of a column from a table in jQuery into a multidimentional array

ホットタグ

アーカイブ