We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,931 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Finding substring in string

0
By iau on Jun 18th, 2011 5:25 pm

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>";

?>

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
*/
diafol
Keep Smiling
Moderator
10,644 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,509
Skill Endorsements: 57

done, many thanks

iau
Newbie Poster
17 posts since May 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

OK, mark as solved then.

diafol
Keep Smiling
Moderator
10,644 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,509
Skill Endorsements: 57

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0589 seconds using 2.65MB