- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Explain array_diff() in PHP
PHP offers different kinds of inbuilt functions having particular functionalities. The array_diff() is a predefined function in PHP and is utilized to figure the distinction between at least two arrays. If we utilize this function with two arrays it returns an array containing every element from array1 that are absent in the other arrays.
This function figures the difference between two or more arrays as per the values of the present inside the arrays.
<?php $myarray1 = array('c', 'd', 'j', 'k', 'c','d','c'); $myarray2 = array('j', 'k', 'd'); print_r(array_diff( $myarray1, $myarray2)); ?>
Array (  => c  => c  => c )
It compares the elements in their string representation. That is, 2 and '2' are both equivalent for array_diff(). The quantity of reiteration of the component in the first array doesn't make a difference. That is if a component happens multiple times in $array1 and just 1 time in a different array then that element will be omitted in the result.
- K-diff Pairs in an Array in C++
- Explain Encapsulation in PHP.
- Explain Polymorphism in PHP.
- Explain interface in PHP.
- How to use diff command in linux
- Explain abstract class in PHP.
- Explain array_merge() function in PHP.
- Explain array_intersect() function in PHP.
- Explain str_split() function in PHP
- Explain array_map() function in PHP
- Explain substr() function in PHP
- Explain STATIC AND INSTANCE method in PHP.
- array() function in PHP
- Explain final class and final method in PHP.
- Explain difference between Abstraction and Encapsulation in PHP.