PHP array_diff()

📔 : PHP 🔗

array_diff() method , दो या दो से अधिक Arrays का difference return करता है। method में पहले pass किये गए Array के वो elements return करता है जो बाकी Array(s) में नहीं हैं।

PHP array_diff Syntax

array_diff ( array $array , array ...$arrays );

Parameters
  1. $array | required : Array variable जिसे बाकी Array(s) से compare करना है।

  2. ...$arrays | required : Array variables जिन्हे पहले Array से compare करना है , आप कितने ही Array(s) pass कर सकते हैं। लेकिन काम से काम 1 तो pass करना ही पड़ेगा।

  3. Return Value : यह method एक Array return करता है , जिसमे पहले pass किये गए Array के वो सभी elements होते हैं जोबाकी Array(s) में नहीं हैं।

PHP array_diff Example

File : php_array_diff.php

Copy Fullscreen Close Fullscreen
<?php   
  $array1 = array("a" => "green", "red", "blue", "red");
  $array2 = array("b" => "green", "yellow", "red");  
  $result = array_diff($array1, $array2);
  print_r($result);
?>
Output
Array ( [1] => blue )

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook