array process

Discussion in 'PHP' started by vagelism, Sep 14, 2008.

  1. #1
    Hello to all. I have a problem and I would like to have your advice.

    I have an array that holds some duplicate values and I would like to repeat a process as long as the value exists in this array, then to go and check for the next value and if is also duplicate repeat the same process ….etc.


    thanks you for your time
     
    vagelism, Sep 14, 2008 IP
  2. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #2
    function give_apples($person){
    
       echo 'Give '.$person.' an apple <br>';
    
    }//end give_apples 
    
    function give_orange($person){
    
       echo 'Give '.$person.' an orange <br>';
    
    }//end give_orange
    
    
    $class = array('John','Paul','Smith','Paul','John','Paul');     //<--- a duplication array value
    
    foreach($class as $person){
    
       ($person == 'John')?give_apples($person):give_orange($person);
    
    }//end foreach
    PHP:
     
    php-lover, Sep 14, 2008 IP