Answers for "php array_diff"

PHP
4

php find differences between two arrays

<?php
$array1 = array("a" => "green", "red", "blue", "red");
$array2 = array("b" => "green", "yellow", "red");
$result = array_diff($array1, $array2);

print_r($result);
?>

Array
(
    [1] => blue
)
Posted by: Guest on May-07-2020
2

php array to csv

Instead of writing out values consider using 'fputcsv()'.

This may solve your problem immediately.

function array2csv($data, $delimiter = ',', $enclosure = '"', $escape_char = "\\")
{
    $f = fopen('php://memory', 'r+');
    foreach ($data as $item) {
        fputcsv($f, $item, $delimiter, $enclosure, $escape_char);
    }
    rewind($f);
    return stream_get_contents($f);
}

$list = array (
    array('aaa', 'bbb', 'ccc', 'dddd'),
    array('123', '456', '789'),
    array('"aaa"', '"bbb"')
);
var_dump(array2csv($list));

/*
I hope it will help you.
Namaste
Stay Home Stay Safe
*/
Posted by: Guest on May-30-2020
6

array_diff php

<?php
$arr_1 = array("a" => "car", "b" => "plane", "c" => "boat", "d" => "bike");
$arr_2 = array("e" => "car", "f" => "plane", "g" => "boat");

$result = array_diff($arr_1, $arr_2);
print_r($result);

/* Result:
Array
(
    [d] => bike
)
 */
Posted by: Guest on May-15-2020
5

array_diff

<?php
$array1 = array("a" => "green", "red", "blue", "red");
$array2 = array("b" => "green", "yellow", "red");
$result = array_diff($array1, $array2);
?>

Array
(
    [1] => blue
)
Posted by: Guest on May-20-2020
1

php array_diff

PHP function array_diff(array $array1, array $array2, array ...$_) int[]
--------------------------------------------------------------------  
Computes the difference of arrays.
  
Parameters:
array--$array1--The array to compare from
array--$array2--An array to compare against
array--...$_--[optional]
  
Returns: an array containing all the entries from array1 that are not present in any of the other arrays.
Posted by: Guest on September-11-2021

Browse Popular Code Answers by Language