HOME BLOG PORTFOLIO PHOTO CONTACT Admin Login
This program should return an array of two strings as output but NOT present in str2

 Write a PHP program which takes two strings as input from the user (str1 and str2).<br>

This program should return an array of two strings as output (op1 and op2).<br>
op1 should contain all the characters which are present in str1 but NOT present in str2.<br>
op2 should contain all the characters which are present in str2 but NOT present in str1.
 
Example1:
Input1 : ABC
Input2 : BC
Outpt = A
 
Example2:
Input1 : BC
Input2 : BANGALORE
Outpt = C
 
 
Answer:
<?php
//BC BANGALORE = C
//ABC BC = A
//processStrings('BC','BANGALORE');
processStrings('ABC','BC');
 
 
function processStrings($str1, $str2) {
    //echo strlen($str2);
    $finalString = '';
    for($i=0; $i<strlen($str1); $i++){
        //echo "=".$str1[$i];
        //Logic start
        $jay1 = $str2;
        $jay2 = $str1[$i];
 
        if (strpos($jay1,$jay2) !== false) {
            //echo "n $jay1 contains $jay2";
        }else{
            $finalString.=$jay2;
        }
        //logic close
        
    }//for close
    echo "n Result=".$finalString;
}
?>
   Share on Facebook

Page views:414