User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,596 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,407 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2058 | Replies: 1
Reply
Join Date: Sep 2007
Posts: 13
Reputation: bhakti.thakkar is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bhakti.thakkar bhakti.thakkar is offline Offline
Newbie Poster

Comparing two arrays problem

  #1  
Sep 8th, 2007
hello all,
i have a php page in which user added certain combinations and clicks on add. when added, i create a array which stores the values and user can add multiple rows.
if ($action=="Add") {
$Arr[] = array (
"scopeid" => $scopeid, // values are comma seperated e.g 1,5,6
"basis" => $basis,
"rate" => $rate,
"currencyid" => $currencyid
);
}

i save it to DB. while editing any of the rows in edit mode, i should create a new version of the latest updates. i have tried to do it but could not do it
how to do this comparison. below is my code. hope some one will help me with it
// $arrar1 = values from DB
// $arrar2 = current page values
// or vice versa
function Array_Compare($array1, $array2) {

if (count($array1) != count($array2) ) { // no further comparison reqd
$NewVersionFlag=1; // new version reqd
return $NewVersionFlag;
} else {
$NewVersionFlag=0; // check further values
}

if ($NewVersionFlag==0) {
// comparing of values goes here
}
return $NewVersionFlag;
} // end function

Completely lost
Thanks in advance
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2006
Location: Bucharest
Posts: 61
Reputation: Eko is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
Eko's Avatar
Eko Eko is offline Offline
Junior Poster in Training

Re: Comparing two arrays problem

  #2  
Sep 8th, 2007
U can use the array_search() function
http://www.php.net/array_search
Make sure u use the "===" for comparising.
It should look something like this :
if ($NewVersionFlag==0) 
{ 
   $i=0;
   foreach($array1 as $value)
   {
         if( array_search($value,$array2) !== 0  )
                  ++$i;
    }
    if( $i == count($array2) )
             echo 'The two arrays have the same values';
    else
             echo 'The arrays do not correspond'
}
Last edited by Eko : Sep 8th, 2007 at 4:38 pm.
"Get rich or die tryin"(50-cent)
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 6:56 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC