Re: different value in array

From: Date: Sat, 29 Jul 2006 10:13:10 +0000
Subject: Re: different value in array
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-239872@lists.php.net to get a copy of this message
Nice tip Paul. Weetat, I'm a bit concerned about your data as I look at it, and think the approach I mentioned before needs a rewrite: Do you have a a "primary key" in your arrays/rows? Meaning, how can you tell if the two arrays you're comparing are just plain _different_, or simply out of synch? Is it your card_serial_no? or card_model? Or another column (like 'id') that you're not passing? The point is, you need to know which is your "primary key" column and do your testing based on these. Then I think your whole update/new/delete/skip process might require two passes: One to handle the update/skip assignments, and another for the new/delete assignments. Use a combo of array_intersect() and array_diff() to help you figure out what needs what... HTH, John W On 7/29/06, Paul Novitski <paul@juniperwebcraft.com> wrote:
At 12:20 AM 7/29/2006, Paul Novitski wrote: You might consider concatenating all the elements in each sub-array to make the comparison logic simpler, e.g.:
        foreach ($currenttablearr as $key => $subarray)
        {
                $comparisonArray[$key] = explode("_", $subarray);
        }
This would result in:
        $comparisonArray[0] == "1235_Malaysia_cd-12345_ws8950"
        $comparisonArray[1] == "1235_Singapore_cd-890_ws1234"
Sorry, of course I meant implode(), not explode()! http://php.net/implode Paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#239872) next »