Questions tagged [array-intersect]

PHP's array_intersect() function accepts the array with master values to check, an array to compare values against and a variable list of arrays to compare. It returns an array containing all of the values in master array whose values exist in all of the parameters.

PHP's array_intersect() function accepts the array with master values to check, an array to compare values against and a variable list of arrays to compare. It returns an array containing all of the values in master array whose values exist in all of the parameters.

169 questions
0
votes
2 answers

Find arrays that share a common value from collection of arrays. May be 0 or more matches

I have the following data structure: array (size=3) 0 => array (size=4) 0 => string 'apple' (length=5) 1 => string 'colophon' (length=8) 2 => string 'byo-fusion-drive' (length=16) 3 => string 'scroll-targeting'…
DarkBlue
  • 33
  • 6
0
votes
3 answers

Find arrays that are fully represented in a flat array with many values

This is the third time that I'm posting about this topic. User Baba helped me everytime. Since the SO website has not a user message system -unfortunately- I'm asking a question within a post. Again. With the help of the user Baba, we have managed…
mozcelikors
  • 2,582
  • 8
  • 43
  • 77
-1
votes
1 answer

php array comparison using diff and intersect seems not giving the result i need

I have 2 arrays $a = array("1", "2", "3", "4", "5"); $b = array("3", "4", "5", "6", "7"); I want the final result be ("6", "7") It seems that array_diff() and array_intersect() can't give the result that I need.
Hang
  • 1
-1
votes
1 answer

array_intersect and match multiple values same time

In this script, you can see i try validate if 2 values - Jhon 34 -there are in the string called $values the same time, when i send the search i use 2 o 3 words and the idea it´s verification if find exactly this 3 or 2 words, etc, inside…
-1
votes
2 answers

Php multidimensional array filter and sum

i've a multidimensional array like this one: ['2021-04-01'=> ['hb' => 35, 'fb' => 40, 'ai' => 50], '2021-04-02'=> ['hb' => 35, 'fb' => 40, 'ai' => 50], '2021-04-03'=> ['hb' => 40, 'ai' => 55], '2021-04-04'=> ['hb' => 40, 'fb'…
-1
votes
1 answer

Matching partial assoc array in bigger assoc array

I have two arrays: $array1 = [ 'user_id' => '1234567890', 'customer_id' => [ '889599494514048876' => [admin => true], '006994743818411627' => [admin => false], '259960192293339276' => [admin => false] …
David
  • 99
  • 6
-1
votes
2 answers

Array intersection for array of objects

I have an array of arrays of objects, and I'm trying to get the intersection of objects found in all of the inner arrays. My first attempt was to use the spread operator on the outer array and pass that to…
Chris Haas
  • 53,986
  • 12
  • 141
  • 274
-1
votes
1 answer

combining single and multidimensional array in php

single dimensional array $arr1 = array(3) { ["Gold"]=> "170" ["Diamond"]=> "301" ["Platinum"]=> "302" } multidimensional array $arr2 = array(3) { [0]=> array(2) { ["ID"]=> "p103" ["PID"]=> "301" } [1]=> array(2) { …
-1
votes
2 answers

Compare two 2D arrays & get intersection and differences

I have two multidimensional arrays with me.. $array1 = [ ['sight_id' => 13, 'location' => 'Jodhpur, Rajasthan, India'], ['sight_id' => 14, 'location' => 'Jodhpur Jn, Jodhpur, Rajasthan, India'], ['sight_id' => 15, 'location' =>…
-1
votes
2 answers

php multidimensional arrays updating based on keys

I have two arrays inventoryStock and posStock (point of sale stock) they both use product sku numbers as the key and the value is the quantity on hand I need to somehow update the posStock with the values from $inventoryStock where there keys are…
-1
votes
3 answers

Find matching items in array

Absolutely doing my head in here over something that I'm sure is very simple... I have 2 arrays. $post_cats which are categories that any given post is in. $ad_cats which is an array of categories in which ads are placed. Basically, if a post has…
Mark
  • 407
  • 7
  • 17
-2
votes
2 answers

Filter 2d array by multiple columns in another 2d array which doesn't contain all columns in the first array

I have below two arrays: $a = [ ['code' => '123', 'name' => 'ABC',], ['code' => '456', 'name' => 'XYZ',], ]; $b = [ ['code' => '123', 'name' => 'ABC', 'price' => '34'], ['code' => '456', 'name' => 'PQR', 'price' => '56'], …
-2
votes
1 answer

PHP Intersect Mutlidimensional Array with Indexed Array

I am trying to intersect an multidimensional array with an indexed array and return matching sku's. Below are my array $products=[ { "id": "6", "sku": "a", }, { "id": "15", "sku": "b", }, { …
blakcaps
  • 2,647
  • 10
  • 46
  • 71
-2
votes
4 answers

Compare and replace values in array

I need compare 2 arrays , the first array have one order and can´t change , in the other array i have different values , the first array must compare his id with the id of the other array , and if the id it´s the same , take the value and replace…
-2
votes
1 answer

check value containing words implode / different array with array intersect

I wanted to check to enter data into the database.Checks are as follows $implode1 = "cat, dog, chicken"; $implode2 = "cow, goat, cat"; If the cat in the variable $implode1 is also contained in the variable $implode2, it should display a warning…
user1798945
  • 145
  • 1
  • 2
  • 7
1 2 3
11
12