par
nico63800 » 18 déc. 2013, 01:34
salut, tu peux faire une fonction pour çà
function somme_si($tab,$min,$max) {
$v1 = $v2 = 0;
foreach($tab as $t) {
if($t[0]>=$min && $t[0]<=$max) {
$v1 += $t[1];
$v2 += $t[2];
}
};
return $result = array($v1,$v2);
}
//--------------------------------------------------------------
$tab = array();
$tab[] = array(0 => 20131202, 1 => 50, 2 => 50 );
$tab[] = array(0 => 20131206, 1 => 90, 2 => 100 );
$tab[] = array(0 => 20131207, 1 => 21, 2 => 20 );
$tab[] = array(0 => 20131209, 1 => 59.1, 2 => 70 );
$tab[] = array(0 => 20131210, 1 => 9.9, 2 => 10 );
$tab[] = array(0 => 20131211, 1 => 82, 2 => 80 );
//--------------------------------------------------------------
$result = somme_si($tab,'20131205','20131208');
var_dump($result);
affiche:
array(2) { [0]=> int(111) [1]=> int(120) }
salut, tu peux faire une fonction pour çà
[php]
function somme_si($tab,$min,$max) {
$v1 = $v2 = 0;
foreach($tab as $t) {
if($t[0]>=$min && $t[0]<=$max) {
$v1 += $t[1];
$v2 += $t[2];
}
};
return $result = array($v1,$v2);
}
//--------------------------------------------------------------
$tab = array();
$tab[] = array(0 => 20131202, 1 => 50, 2 => 50 );
$tab[] = array(0 => 20131206, 1 => 90, 2 => 100 );
$tab[] = array(0 => 20131207, 1 => 21, 2 => 20 );
$tab[] = array(0 => 20131209, 1 => 59.1, 2 => 70 );
$tab[] = array(0 => 20131210, 1 => 9.9, 2 => 10 );
$tab[] = array(0 => 20131211, 1 => 82, 2 => 80 );
//--------------------------------------------------------------
$result = somme_si($tab,'20131205','20131208');
var_dump($result);[/php]
affiche:
array(2) { [0]=> int(111) [1]=> int(120) }