1
2<?php
3$array1 = array("a" => "green", "red", "blue", "red");
4$array2 = array("b" => "green", "yellow", "red");
5$result = array_diff($array1, $array2);
6
7print_r($result);
8?>
9
10Array
11(
12 [1] => blue
13)
1Instead of writing out values consider using 'fputcsv()'.
2
3This may solve your problem immediately.
4
5function array2csv($data, $delimiter = ',', $enclosure = '"', $escape_char = "\\")
6{
7 $f = fopen('php://memory', 'r+');
8 foreach ($data as $item) {
9 fputcsv($f, $item, $delimiter, $enclosure, $escape_char);
10 }
11 rewind($f);
12 return stream_get_contents($f);
13}
14
15$list = array (
16 array('aaa', 'bbb', 'ccc', 'dddd'),
17 array('123', '456', '789'),
18 array('"aaa"', '"bbb"')
19);
20var_dump(array2csv($list));
21
22/*
23I hope it will help you.
24Namaste
25Stay Home Stay Safe
26*/
1<?php
2$arr_1 = array("a" => "car", "b" => "plane", "c" => "boat", "d" => "bike");
3$arr_2 = array("e" => "car", "f" => "plane", "g" => "boat");
4
5$result = array_diff($arr_1, $arr_2);
6print_r($result);
7
8/* Result:
9Array
10(
11 [d] => bike
12)
13 */
14
1<?php
2$array1 = array("a" => "green", "red", "blue", "red");
3$array2 = array("b" => "green", "yellow", "red");
4$result = array_diff($array1, $array2);
5?>
6
7Array
8(
9 [1] => blue
10)
1PHP function array_diff(array $array1, array $array2, array ...$_) int[]
2--------------------------------------------------------------------
3Computes the difference of arrays.
4
5Parameters:
6array--$array1--The array to compare from
7array--$array2--An array to compare against
8array--...$_--[optional]
9
10Returns: an array containing all the entries from array1 that are not present in any of the other arrays.
1<?php
2$array1 = array("a" => "green", "red", "blue", "red");
3$array2 = array("b" => "green", "yellow", "red");
4$result = array_diff($array1, $array2);
5
6print_r($result);
7?>