<?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>";
/****/
for( $i=0; $i < count($double) ; $i++)
{
if( $double[$i] != "none" )
{
$arrayCurrentRecord = array();
$arrayCurrentRecord = $record[$i];
$loop = true;
while ($loop)
{
if (($pos = array_search($double[$i] , $arrayCurrentRecord)) !== false)
{
unset($arrayCurrentRecord[$pos]);
}
else
{
$loop = false;
$rebuild[] = $arrayCurrentRecord;
}
}
}
else
{
$rebuild[] = $record[$i]; //$arrayCurrentRecord;
//print_r($record[$i]);
}
}
echo "<BR>";
echo "<pre>";
echo " ********* REBUILD ***************";
echo "<BR>";
print_r($rebuild);
echo "</pre>";
echo " ************************";
echo "<BR>";
$tabIndexed = array();
// probléme : ne se comporte pas comme prévu ????
////$tabIndexed = array_values($rebuild);
for( $i=0; $i < count($rebuild) ; $i++)
{
$chaine = implode(" ", $rebuild[$i]);
echo "String " .$chaine ."\n";
$pieces = explode(" ", $chaine);
$tabIndexed[] = $pieces;
}
echo "<BR>";
echo "<pre>";
echo " ********* Re-index ***************";
echo "<BR>";
print_r($tabIndexed);
echo "</pre>";
echo " ************************";
echo "<BR>";
/*for( $i=0; $i < count($rebuild) ; $i++)
{
$tmp = array();
for( $j=0; $j < count($rebuild[$i]) ; $j++)
{
$tmp[] = $rebuild[$i][$j];
}
$tabIndexed[] = $tmp;
}
print_r($tabIndexed);*/
for( $i=0; $i < count($tabIndexed) ; $i++)
{
$arrayCurrentRecord = array();
$arrayCurrentRecord = $tabIndexed[$i];
//print_r($reIndex[$i]);
for( $j=0; $j < count($arrayCurrentRecord) ; $j++)
{
echo $rebuild[$i][$j];
for( $k=0; $k < count($arrayObjClient) ; $k++)
{
if( $arrayObjClient[$k]->getNom() == $arrayCurrentRecord[$j] )
{
if( $arrayObjClient[$k]->getSimplePremiere() == 0)
{
$arrayObjClient[$k]->setSimplePremiere(1);
echo " Premier \n";
}
else //if( $arrayObjClient[$k]->getDoublePremiere() == 1)
{
$arrayObjClient[$k]->setSimpleAutre($arrayObjClient[$k]->getSimpleAutre() + 1);
echo " Multiple \n";
//$arrayObjClient[$k]->incrementDoubleAutre();
}
}
}
}
}
echo "<BR>";
echo "<pre>";
echo " ********* OBJECTS ***************";
echo "<BR>";
print_r($arrayObjClient);
echo "</pre>";
echo " ************************";
echo "<BR>";
echo " ------------------------------------ \n";
echo " ------------------------------------ \n";
echo " ------------------------------------ \n";
echo " ------------------------------------ \n";
/*
$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++;
}
/****/
}
?>