hy all, how to get previous value and check different between recently value and previous values in loop < 0.5?
if different value < 0.5 get it's array
please help me

define('DIV', 0.5);
function iteration($data, $data2)
    {
    $m1=$m2=$data;
    $m3=multiply($m1,$m2);
    echo "iteration 1:\n";
    print_r($m3);
    $temp_m3 = $m3;

    for ($i=0;$i<count($temp_m3);$i++)
            {
                for ($j=0;$j<count($temp_m3[$i]);$j++)
                 {
                 if (isset($data2[$i][$j])){
                 $aR[]  = (($temp_m3[$i][0]*$data2[$i][$j])+($temp_m3[$i][1]*$data2[$i][$j])+($temp_m3[$i][2]*$data2[$i][$j]));
                 }
        }
    }
    print_r($aR);

    echo $max = max($aR)."<br/>";
    for($a=0; $a<count($aR);$a++){
    $bg_max[] = $max/$aR[$a]; 
    }  
    print_r($bg_max);

    $m1=$m2=$m3;

    for($c=2;$c<=7;$c++)
    {
    $m3=multiply($m1,$m2);
    echo "iteration $c:\n";
    print_r($m3);
    $m1=$m3;

    $aR2 = array();
    for ($x=0;$x<count($m3);$x++)
            {
                for ($y=0;$y<count($m3[$x]);$y++)
                 {
                 if (isset($data2[$x][$y])){
                 echo "value aR=> ".$aR2[]  = (($m3[$x][0]*$data2[$x][$y])+($m3[$x][1]*$data2[$x][$y])+($m3[$x][2]*$data2[$x][$y]))."<br/>";
                 }

    }

    }
    echo $max2 = max($aR2);
    $temp_max = array();
    $bagi_max2 = array();
    for($b=0; $b<count($aR2);$b++){
     $bg_max2[] = $max2/$aR2[$b];
     $temp_max[] = $max2/$aR2[$b];

    }
    print_r($bg_max2);
    print_r($temp_max);


    //DIV = 0.5
    //how to check different value below? 
     if(????????????){
        if((??????????????$bg_max2 - $bg_max< DIV){

            return $bg_max2;
        }

    }else{
        if((??????????????????? = $bg_max2 - $temp_max < DIV)){
            return $bg_max2;
        } 
    } 




    }

}
    echo "<pre>";
    $result_iteration = iteration($data,$data2);
    echo "</pre>";

Hai;

Chek the given example

<?php
$fetch_row = array("1","2","3","4","5","6","7","7.2","9","10","10.3");
foreach  ($fetch_row as $key=>$myRow) {
    if($key>0){
        $difference = $myRow-$previousValue;
        echo "different between ".$myRow." and ".$previousValue." = ".$difference."<br />";
        if($difference< 0.5) echo "Your difference is < 0.5.";
        echo "<hr />";

    }
    $previousValue = $myRow;
}

?>

can you give me example in array 2D?
like this:

$fetch_row = array(
    array(1,2,7),
    array(3,4,9),
    array(5,6,5)
);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.