<?php $record = array ( array("aaa","bbb"), array("BMW"), array("nnn","nnn","ppp"), array("un","deux","trois","trois" ), array("un","deux","trois","trois","quatre" ), array("un","deux","trois","trois","quatre", "lule" ), array("un","deux","trois","trois","quatre", "lule", "plouf" ), array("un","deux","trois","trois","quatre", "lule", "one", "two" ) ); $all_client_month = array(); /* concatenation de tous les clients qui ont fait une réservation dans le mois */ for( $i=0; $i < count($record) ; $i++) { $all_client_day = array(); $all_client_day = $record[$i]; for( $j=0; $j < count($all_client_day) ; $j++) { $all_client_month[] = $all_client_day[$j]; } } echo "<BR>"; echo "<pre>"; print_r($all_client_month); echo "<BR>"; echo "<pre>"; /* supprimer les doublons */ $all_client_month_no_doublons = array_unique($all_client_month); echo "<pre>"; print_r($all_client_month_no_doublons); echo "</pre>"; /* création des objets */ foreach ($all_client_month_no_doublons as $valeur) { $arrayObjClient[] = new Personne($valeur); } echo "<BR>"; echo "<pre>"; echo " ********* OBJECTS ***************"; echo "<BR>"; print_r($arrayObjClient); echo "</pre>"; echo " ************************"; echo "<BR>"; for( $k=0; $k < count($arrayObjClient) ; $k++) { echo $arrayObjClient[$k]->getNom() ."\n"; } $double = array(); for( $i=0; $i < count($record) ; $i++) { $arrayCurrentRecord = array(); $arrayCurrentRecord = $record[$i]; echo "<pre>"; print_r($arrayCurrentRecord); echo "</pre>"; $flag = false; // 0 1 2 3 < 4 for( $j=0; $j < count($arrayCurrentRecord) ; $j++) { if( count($arrayCurrentRecord) == 1 ) { echo(" ------------ " .$arrayCurrentRecord[$j] ."\n"); } if( $j <= count($arrayCurrentRecord) - 2 ) // 4 - 1 { // 0 1 // 1 2 // 2 3 //echo(" Compare " .$arrayCurrentRecord[$j] ." " .$arrayCurrentRecord[$j+1] ."\n"); $mess = " Compare " .$arrayCurrentRecord[$j] ." " .$arrayCurrentRecord[$j+1]; if($arrayCurrentRecord[$j] == $arrayCurrentRecord[$j+1]) { echo $mess ." --> Doublon " .$arrayCurrentRecord[$j] ."\n"; echo " Traitement " ."\n"; $flag = true; $double[] = $arrayCurrentRecord[$j]; for( $k=0; $k < count($arrayObjClient) ; $k++) { $mess = $arrayObjClient[$k]->getNom() ." ? " .$arrayCurrentRecord[$j]; if( $arrayObjClient[$k]->getNom() == $arrayCurrentRecord[$j] ) { echo $mess ." yes "; if( $arrayObjClient[$k]->getDoublePremiere() == 0) { $arrayObjClient[$k]->setDoublePremiere(1); echo " Premier \n"; } else //if( $arrayObjClient[$k]->getDoublePremiere() == 1) { $arrayObjClient[$k]->setDoubleAutre($arrayObjClient[$k]->getDoubleAutre() + 1); echo " Multiple \n"; //$arrayObjClient[$k]->incrementDoubleAutre(); } } else { echo $mess ."\n"; } } } else { echo $mess ."\n"; } } } if( $flag == false) { $double[] = "none"; } echo("-----------------------" . "\n"); } echo "<BR>"; echo "<pre>"; echo " ********* DOUBLE ***************"; echo "<BR>"; print_r($double); echo "</pre>"; echo " ************************"; echo "<BR>"; echo "<BR>"; echo "<pre>"; echo " ********* OBJECTS ***************"; echo "<BR>"; print_r($arrayObjClient); echo "</pre>"; echo " ************************"; echo "<BR>"; $rebuild = array(); /* Traitement des reservations simple */ for( $i=0; $i < count($record) ; $i++) { $arrayCurrentRecord = array(); $arrayCurrentRecord = $record[$i]; $vals = array_count_values($arrayCurrentRecord); echo " vvvvvvvvvvvvvvvvvvvvvvvvvvvvv " ."\n"; echo 'No. of NON Duplicate Items: '.count($vals).'<br><br>'; print_r($vals); $tmp = array(); $flag = false; foreach($vals as $key => $value) { //echo "key=" . $key . ", Valeur=" . $value; //echo "<br>"; if( $value == 1 ) { //$rebuild[] = $key;aaaa $tmp[] = $key; $flag = true; echo " --> " .$key ."\n"; } if( $value == 11) { echo "JOB" ."\n"; $loop = true; while ($loop) { if (($pos = array_search($key, $arrayCurrentRecord)) !== false) { unset($arrayCurrentRecord[$pos]); } else { $loop = false; $rebuild[] = $arrayCurrentRecord; } } } } //if( $flag == true ) if( ! empty($tmp) ) { //$rebuild[] = $tmp; //echo "<BR>"; //print_r($tmp); //echo "</pre>"; //echo "\n"; } } echo "<BR>"; echo "<pre>"; echo " ********* OBJECTS ***************"; echo "<BR>"; print_r($rebuild); echo "</pre>"; echo " ************************"; echo "<BR>"; /*$tab = array('world','hello','good','hello'); $element = 'hello'; unset($tab[array_search($element, $tab)]); echo "<BR>"; print_r($tab); echo "</pre>";*/ // php remove 2 consecutive word in string // https://www.geeksforgeeks.org/delete-consecutive-words-sequence/ //if (in_array("100", $marks)) ?> <?php class Personne { private $nom; private $simple_premiere = 0; private $simple_autre = 0; private $double_premiere = 0; private $double_autre = 0; public function __construct($nom) { $this->nom = $nom; } public function setNom($val) { $this->nom = $val; } public function getNom() { return $this->nom; } /****/ public function setSimplePremiere($val) { $this->simple_premiere = $val; } public function getSimplePremiere() { return $this->simple_premiere; } /****/ public function setSimpleAutre($val) { $this->simple_autre = $val; } public function getSimpleAutre() { return $this->simple_autre; } public function incrementSimpleAutre() { $simple_autre++; } /****/ public function setDoublePremiere($val) { $this->double_premiere = $val; } public function getDoublePremiere() { return $this->double_premiere; } /*****/ public function setDoubleAutre($val) { $this->double_autre = $val; } public function getDoubleAutre() { return $this->double_autre; } public function incrementDoubleAutre() { $double_autre++; } /****/ } ?>