Location: PHPKode > scripts > class_arrays > class_arrays/class_arrays.php
<?php
/****************************************************************
*****************************************************************

class_log.php: create to work with log file (create and search).
Copyright (C) 2003  Matthieu MARY hide@address.com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

You can found more information about GPL licence at:
http://www.gnu.org/licenses/gpl.html

for contact me: hide@address.com
****************************************************************
****************************************************************/
/**
 * create the : july 9th 2003.
 * @author      Matthieu MARY
 * @since       1.0
 */
class arrays{
    var $aArrays;

    /**
	 * Builder
	 *
	 * @public
	 * @param array aArray, optional, default value array(); an array
     * @type void
	 */
    function arrays($aArray=array()){
        $this->aArrays = $aArray;
    }//arrays

     /**
	 * Function that return a string which each of values of the array
	 *
	 * @public
	 * @param string sep, optional,default value ','; a character that will delimit each char in line
     * @type string
	 */
     function line($sep=','){
        // make a string with values of the array
        $sString = '';
        for ($i = 0; $i < $this->size();$i++) $sString .= $sep.$this->aArrays[$i];
        return substr($sString,strlen($sep));
     } // line

     /**
	 * Method that will does a array_push for each array element pass in parameter
	 *
	 * @public
	 * @param array oObj, required. the array to add to the object
     * @type void
	 */
     function add(&$oObj){
        if (is_array($oObj)){
            foreach($oObj as $number => $value) array_push($this->aArrays,$value);
        }
     } // add()
     
     /**
	 * Function that returns the object
	 *
	 * @public
     * @type array
	 */
    function get(){
        return $this->aArrays;
    }// get
    
     /**
	 * Method that remove some datas from an array
	 *
	 * @param string svalue_to_remove, required. the value to remove from the array
	 * @public
	 */
    function arrayshift($sValue_to_remove){
        $dArray_copy = array();
        foreach($this->aArrays as $key => $value){
            if (trim($value) != $sValue_to_remove) $dArray_copy[$key] = $value;
        }
        $this->aArrays = $dArray_copy;
        unset($dArray);
    }//arrayshift
    
    /**
	 * Method add a value to the array
	 *
	 * @param string svalue, required. the value to add to the array
	 * @param mixed skey, optional. the key of the value to add
	 * @public
	 * @type void
	 */
    function set_value($svalue,$skey=-1){
        if (trim($svalue)!=''){
            if ($skey != -1) $this->aArrays[$skey] = $svalue;
            else $this->aArrays[] = $svalue;
        }
    }

    /**
	 * Function that returns the size of the array = count($this->arrays)
	 *
	 * @public
	 * @type int
	 */
    function size(){
        return count($this->aArrays);
    }
    
    /**
	 * Method that clear the array
	 *
	 * @public
	 * @type void
	 */
    function reinitialise(){
      $this->aArrays = array();
    }
    
    /**
	 * Method that remove some values or keys when they are on the array parameter
	 *
	 * @param array aArrays, required. the array with value to remove
	 * @param bool bOnkey, optional, default value FALSE; the value to remove are keys of parameters?
	 * @public
	 * @type void
	 */
    function remove(&$aArrays,$bOncle=FALSE){
        $aTemp = array();
        $aCles = array_keys($aArrays);
        $aValues = array_values($aArrays);
        foreach($this->aArrays as $cle => $valeur){
            if ($bOncle){ if (!in_array($cle,$aCles)) $aTemp[$cle] = $valeur;}
            else { if(!in_array($valeur,$aValues)) $aTemp[$aCle] = $valeur;}
        }
        $this->aArrays = $aTemp;
    }

}// class
?>
Return current item: class_arrays