Error in code.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
afbase
Forum Contributor
Posts: 113
Joined: Tue Aug 15, 2006 1:29 pm
Location: SoCAL!!!!

Error in code.

Post by afbase »

I'm shaking off some rust in my php code for some math homework.
I get this problem when i run the code.
Parse error: syntax error, unexpected '[' in /home/clinton/test.php on line 30
This error corresponds to this line:

Code: Select all

q[$i][x]=p[$i-1][x];
[/b]
in the following code

Code: Select all

<?
//Vectors
$p[0][x] = 0;
$p[0][y] = 0;
 
$p[1][x] = 1;
$p[1][y] = 2;
 
$p[2][x] = 2;
$p[2][y] = 2;
 
$p[3][x] = 3;
$p[3][y] = 0;
 
//knot vectors
$knot = array (0,0,0,0,1,1,1,1);
$j = 1;
$t_prime = 1/2;
//division
for ($i=0; $i == 4; $i++){
if ($i <= $j - 1){
$q[$i][x]=$p[$i][x];
$q[$i][y]=$p[$i][y];
}
else if ($i>= $j && $i<=$j+2){
$q[$i][x]=(1-(($t_prime - $knot[$i-2])/($knot[$i+1]-$knot[$i-2])))*$p[$i-1][x]+(($t_prime - $knot[$i-2])/($knot[$i+1]-$knot[$i-2]))*$p[$i][x]; 
$q[$i][y]=(1-(($t_prime - $knot[$i-2])/($knot[$i+1]-$knot[$i-2])))*$p[$i-1][y]+(($t_prime - $knot[$i-2])/($knot[$i+1]-$knot[$i-2]))*$p[$i][y];
}
else if($i>=$j+3){
q[$i][x]=p[$i-1][x];
q[$i][y]=p[$i-1][y];
 
}
else();
}
 
print_r($q);
 
 ?>
I'm using vim as my IDE, but I think my rust is overwhelming. Thanks for any help :D
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Error in code.

Post by Mark Baker »

string values that are array indexes should be quoted, and you need to use a dollar sign to indicate variables as well:
so

Code: Select all

q[$i][x]=p[$i-1]'x];
becomes

Code: Select all

$q[$i]['x']=$p[$i-1]['x'];
afbase
Forum Contributor
Posts: 113
Joined: Tue Aug 15, 2006 1:29 pm
Location: SoCAL!!!!

Re: Error in code.

Post by afbase »

thanks
Post Reply