In PHP, to push the value in an array on match we need an array with key and value pair. An array which contains key and value pair is known as associative array.
Approach: Create two different associative array named as array1 and array2. Then compare the value of array1 with the key of array2 and if we get a match then we will push a static key and value pair as follows:
In the above program, the value is pushed in an existing array. If you want to push value in a whole new array then see the below program.
The above program will push the values from the array2 to array3 where the array3 is empty.
Array ( [IT] => Array ( [total_students] => 60 [HOD] => XYZ ) [CE] => Array ( [total_students] => 65 [HOD] => XYZ ) [CS] => Array ( [total_students] => 62 [HOD] => XYZ ) )
In the above program, there is no match for the dept4 in the student array so that it is not displayed in the output section.
- Difference between Memory based and Register based Addressing Modes
- Difference between Preemptive Priority based and Non-preemptive Priority based CPU scheduling algorithms
- PHP Ds\Queue push() Function
- PHP Ds\PriorityQueue push() Function
- PHP | Ds\Stack push() Function
- PHP | Ds\Sequence push() Function
- PHP | Ds\Vector push() Function
- PHP | Ds\Deque push() Function
- Node.js | push() function
- PHP | SplDoublyLinkedList push() Function
- p5.js | Push Operation on Stack
- ConcurrentLinkedDeque push() method in Java with Examples
- Perl | Arrays (push, pop, shift, unshift)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.