Hi all,

Got something that's driving me mad!!

Got a 2d array, which I'm putting through a simple mathematical equation then putting the new values into another array.

$line d2 is an array which represents a table.
$line[0] is the y axis label and $line[0][$i] is the value for the particular column.


When you run the script below, you’ll see a table with a x/y axis starting from 0 incrementing by .25 up to 2 on the x axis and 6 on the y.

In the cells of the first table are the position and value that ‘SHOULD’ be inserted into the new array [$pLine]: ie: 0:9 (R1:5) = $pLine[0][9]=$R1:5


I'm thinking that the line:
PHP Code:
$pLine[$new][$i]=$line[$iy][$i]; 
should swap the value into the new array. But as you can see when you run the script, this isn’t happening??

Any pointers?
TIA


So far I’ve got:

PHP Code:
<?php

$line
[] = array('0.00','R1:5','0','0','0','0','0','0','0','0');
$line[] = array('0.25','R1:5','R1:5','0','0','0','0','0','0','0');
$line[] = array('0.50','R1:5','R1:5','R1:5','0','0','0','0','0','0');
$line[] = array('0.75','R1:5','R1:5','R1:5','R1:5','0','0','0','0','0');
$line[] = array('1.00','R1:5','R1:5','R1:5','R1:5','R1:5','0','0','0','0');
$line[] = array('1.25','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','0','0','0');
$line[] = array('1.50','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','0','0');
$line[] = array('1.75','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','0');
$line[] = array('2.00','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5');
$line[] = array('2.25','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5');
$line[] = array('2.50','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5');
$line[] = array('2.75','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5');
$line[] = array('3.00','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5');
$line[] = array('3.25','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5');
$line[] = array('3.50','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5');
$line[] = array('3.75','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5');
$line[] = array('4.00','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5');
$line[] = array('4.25','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5');
$line[] = array('4.50','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5');
$line[] = array('4.75','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5');
$line[] = array('5.00','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5');
$line[] = array('5.25','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5','R1:5');
$line[] = array('5.50','R1:5','R1:5','R1:5','R2:5','R2:5','R2:5','R2:5','R2:5','R2:5');
$line[] = array('5.75','R1:5','R1:5','R1:5','R2:5','R2:5','R2:5','R2:5','R2:5','R2:5');
$line[] = array('6.00','R1:5','R1:5','R1:5','R2:5','R2:5','R2:5','R2:5','R2:5','R2:5');

$ii=0;


$pLine=$line;

echo 
"<table><tr><td></td>";
$x=0;
for(
$i=1;$i<count($line[1]);$i++){

echo 
"<td style=\"border-bottom:1px solid #cccccc\">".$x."</td>";
$x=$x+.25;
}
echo 
"</tr>";

$x2=0;
for(
$iy=0;$iy<count($line);$iy++){


    
$pLine[$iy][0]="";

    echo 
"<tr>";
    
$x=0;
    echo 
"<td>".$line[$iy][0]." | </td>";
    unset(
$i);
    
    
    
        for(
$i=1;$i<count($line[$i]);$i++){
    
        
$pLine[$iy][$i]="";
        
        
$new=$line[$iy][0]-$x;
        

        if(
$new<0){$new=$new+6.25;}
        
            if(
$line[$iy][$i]!="0"){
            echo 
"<td bgcolor=\"#cccccc\">&nbsp;".$new.":".$i." (".$line[$iy][$i].")&nbsp;</td>";
            } else {
            echo 
"<td bgcolor=\"#999999\">&nbsp;".$new.":".$i." (".$line[$iy][$i].")&nbsp;</td>";
            }
                
$pLine[$new][$i]=$line[$iy][$i];
        
$pLine[$new][0]="$new";

        
$x=$x+.25;
        }

    
$x2=$x2+.25;
    
echo 
"</tr>";
    
}
echo 
"</table><br><br><br><br><br>";






//creat the new table from $pLine
$line=$pLine;

echo 
"<table><tr><td></td>";
$x=0;
for(
$i=1;$i<count($line[1]);$i++){

echo 
"<td style=\"border-bottom:1px solid #cccccc\">".$x."</td>";
$x=$x+.25;
}
echo 
"</tr>";



for(
$iy=0;$iy<count($line);$iy++){
    echo 
"<tr>";
    
$x=0;
    echo 
"<td>".$line[$iy][0]." | </td>";
    unset(
$i);
    
    
    
        for(
$i=1;$i<count($line[$i]);$i++){
    
    
$new=$line[$iy][0]-$x;
    

        if(
$new<0){$new=$new+6.25;}
        
            if(
$line[$iy][$i]!="0"){
            echo 
"<td bgcolor=\"#cccccc\">&nbsp;".$new.":".$i." (".$line[$iy][$i].")&nbsp;</td>";
            } else {
            echo 
"<td bgcolor=\"#999999\">&nbsp;".$new.":".$i." (".$line[$iy][$i].")&nbsp;</td>";
            }
    
        
$pLine[$new][$i]="$new";
        
        
$x=$x+.25;
        
        }
    
    
//4:9 24:2
    
$x2=$x2+.25;
    
echo 
"</tr>";
    
}
echo 
"</table>";

?>