Zend - The PHP Company




Arrays

Add Code


Simple operations with arrays.  

Type: code fragment
Added by: orfeuRO
Entered: 31/01/2004
Last modified: 02/12/2003
Rating: - (fewer than 3 votes)
Views: 3795
In this simple function you send two arrays and a number x if x is 1 the function will return A+B ( reunion ) and if x it is not 1 will return A%B ( crossing )


<?php

/* Code by Serban Nicolae @2004 orfeu@as.ro
     In this simple function you send two arrays and a number x
         if x is 1 the function will return A+B ( reunion )
         and if x is 2 will return A%B ( crossing ) 
     
*/

function oper_arrays($a ,$b$x=1)
   {
    
$ct1=count($a);
        
$ct2=count($b);

    if (
$x==1) {    $c=$a;
            for (
$i=$i<$ct2 $i++)
                { 
                
$boo=0
                     for (
$j=$j<$ct1 $j++)
                           if (
$b[$i]==$a[$j]) $boo=1;   
                    if (
$boo==0$c[]=$b[$i];

                }
                      return 
$c;
           }

    else       { for (
$i=$i<$ct1 $i++)
                {
                       
$boo=0;
                    for (
$j=$j<$ct2 $j++)
                    if (
$a[$i]==$b[$j]) $boo=1;
    
                        if (
$boo==1$c[]=$a[$i];
                    }
             return 
$c;
           }

   }

?>


Usage Example




Rate This Script





Search



This Category All Categories