Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $a1 = array("a" => "red", "a" => "red", "b" => "green", "c" => "blue", "d" => "yellow");
- $a2 = array("e" => "red", "e" => "red", "f" => "green", "g" => "blue");
- $result = array("d" => "yellow");
- // 0. if no dupes return
- // 1. take a1 and find duplicates
- $a1dupes = array("a" => "red");
- // 2. if a2 NOT include "red" return
- // else if "red"<2 return
- // result:
- $result = array("red");
- function findDupesInBothArrays($arr1, $arr2)
- {
- $a1dupes = array();
- for ($i = 0; $i < count($arr1); $i++) {
- # code...
- $valueToCheck = $arr1[$i];
- for ($j = 0; $j < count($arr1); $j++) {
- # code...
- if ($i == $j) {
- return;
- }
- if ($valueToCheck == $arr1[$j]) {
- // $a1dupes[$key] = $valueToCheck;
- array_push($a1dupes, $valueToCheck);
- }
- }
- }
- // $a1dupes = array("a" => "red");
- for ($i = 0; $i < count($a1dupes); $i++) {
- # code...
- $valueToCheck = $a1dupes[$i];
- for ($j = 0; $j < count($arr2); $j++) {
- # code...
- if ($valueToCheck == $arr2[$j]) {
- // $a1dupes[$key] = $valueToCheck;
- array_push($result, $valueToCheck);
- }
- }
- }
- if (count($result)) {
- return $result;
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement