This was the client round question for code challenge.. Create a PHP function to find the intersection of two arrays. <?php function FindIntersection ( $strArr ) { // Split the strings into arrays and convert to integers foreach ( $strArr as $index => $element ) { $strArr [ $index ] = array_map ( 'intval' , explode ( ',' , $element )); } $main_match_array = $strArr [ 0 ]; array_shift ( $strArr ); $interarray = []; foreach ( $strArr as $each_chunk ) { foreach ( $main_match_array as $in => $number ) { if ( in_array ( $number , $each_chunk )) { $interarray [ $number ] = $number ; } else { unset ( $int...
Time to go through some design patterns used wide in creating the applications. Why do they exists, anyway? Let's go to Observer pattern.See the example below, <?php // Observer interface interface Observer { public function update($message); } // Concrete Observers class EmailSubscriber implements Observer { private $email; public function __construct($email) { $this->email = $email; } public function update($message) { echo "Email sent to {$this->email}: $message\n"; } } class SMSSubscriber implements Observer { private $phone; public function __construct($phone) { $this->phone = $phone; } public function update($message) { echo "SMS sent to {$this->phone}: $message\n"; } } // Subject class NewsPublishe...