1,105,254 Community Members

Finding substring in string

Member Avatar
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I wish it show as
unfulfilled:bb,cc
extra provided:dd
as my conditions and provided strings will be unconstant, anyone can suggest me some ways to do it?

<?php
$condition="aa,bb,cc";
$provided="aa,dd";
$arr1=explode(",",$condition);
$arr2=explode(",",$provided);
$b=0;
$c=0;

//check sizes of arrays
if(count($arr1)>count($arr2))
{
    $size=count($arr1);
    $a=count($arr2);
}
else
{
    $size=count($arr2);
    $a=count($arr1);
}

//compare both arrays
for($i=0;$i<$size;$i=$i+1)
{
    for($j=0;$j<$a;$j=$j+1)
    {
        if($arr1[$i]==$arr2[$j])
        {
            $num=$num+1;                //check number of matched
            $arr3[$b]=$arr1[$i];        //assign matched to new array
            $b=$b+1;
        }
        
    }
}
echo $num.'matched: ';
while($c<$b)
{
    echo $arr3[$c]." ";
    $c=$c+1;
}
echo "<br>";

?>
Member Avatar
diafol
Where are my eyes?
12,940 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,845 [?]
Skill Endorsements: 90 [?]
Moderator
Featured
Sponsor
 
1
 

Try this:

$condition= "aa,bb,cc"; 
$provided= "aa,dd"; 
$array1 = explode(",",$condition);
$array2 = explode(",",$provided);
echo "Unfilled: " . implode(",",array_udiff($array1,$array2, "strcasecmp"));
echo "<br />";
echo "Extra Provided: " . implode(",",array_udiff($array2, $array1, "strcasecmp"));

/*
Unfilled: bb,cc
Extra Provided: dd
*/
Member Avatar
iau
Newbie Poster
17 posts since May 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

done, many thanks

Member Avatar
diafol
Where are my eyes?
12,940 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,845 [?]
Skill Endorsements: 90 [?]
Moderator
Featured
Sponsor
 
0
 

OK, mark as solved then.

You
Post:
Start New Discussion
Tags Related to this Article