compare two arrays and return the difference php
array_merge(array_diff($array1,$array2),array_diff($array2,$array1))
<?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
)
*/
<?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
)
Also in PHP:
- 'https://', 'www.' & all sub derictories reomve from a url with regex
- Problem 1 - phpunit/phpunit[8.5.0, ..., 8.5.x-dev] require ext-dom * -> it is missing from your system. Install or enable PHP's dom extension.
- complete date fromat in php
- current url wordpress
- composer-php version check
- 'cross-env' is not recognized as an internal or external command, laravel
- 01 july 2020 php date format
- 1071 Specified key was too long;
- clearcache artisan
- Illuminate\Http\Request vs \Illuminate\Support\Facades\Request
- console.log() but with php
- create laravel project version 5.8
- daye in php
- exists in laravel array
- find out type of in php
- fetch visitor latitude and longitude using ipaddress php
- compare two arrays and return the difference php
- $product->product_type
- convert am pm time to 24 hour in php
- convertidos de 24 12 hr php
- catching error and pass php
- eloquent firstOrCreate
- email configuration for gmail in laravel
- command line read line by line