comparing two arrays

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
What i need to do is compare two arrays and return an array that only
has those that are not in the main table.It's similar to what you could
do with SQL.

Array 1 - List of Everything
Array 2 - List of Some of Array 1

What i want to obtain is Those of Array 1 that are not in Array 2. I
would prefer not to do the following:

function getUnique($array1, $array2)  {

   foreach ($array1, $key => $value) {
         $array2_key = array_search($array2,$value)

         if ($array2_key === false)
                $result_array[] = $value;


   return $result_array;

Is there any simplier way of doing this...any predefined function in
php that could do this??

Gerard Matthew.

Re: comparing two arrays

Gerard Matthew wrote:
Quoted text here. Click to load it

E. Dronkert

Re: comparing two arrays

Kimmo Laine wrote:
Quoted text here. Click to load it

Unless next_page.php generates PHP, the script with this include will
only get HTML.

Quoted text here. Click to load it


    if (isset($_GET['foo'])) {
      echo '<?php echo $_GET[\'foo\']; ?>';
    } else {
      echo '<?php echo \'Not available\'; ?>';

File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot

Re: comparing two arrays

Isn't it funny how we sometimes reinvent the wheel unpurposely?  I did that
once with $duration in mIRC scripting. hehe.

Quoted text here. Click to load it

Site Timeline