Re: Error in variable assignment

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11 April 2011 20:28, Ethan Rosenberg <ethros@xxxxxxxxxxxxx> wrote:
> Dear list -
>
> I an writing a script that will simulate a chess board. ÂOn a move from e2
> to e6 [see below] the variable in e2 is never assigned to e6. ÂHere are some
> code snippets:
>
> <?php
> session_start();
> session_name("Chess");
> error_reporting(1);
> Âif ($_SESSION['flag'] != 1)
> {
> $flag = 1;
> echo "<br />starting<br />";
> Â$results = array(array("Br", "Bn", "Bb", "Bq", "Bk", "Bb", "Bn",
> "Br"),array("Bp", "Bp", "Bp", "Bp", "Bp", "Bp", "Bp", "Bp"),
> Â Â Â Â Â Â Â Â Â Â Â Âarray("", "", "", "", "", "", "", ""),array("", "",
> "", "", "", "", "", ""),array("", "", "", "", "", "", "", ""),
> Â Â Â Â Â Â Â Â Â Â Â Âarray("", "", "", "", "", "", "", ""),array("Wp",
> "Wp", "Wp", "Wp", "Wp", "Wp", "Wp", "Wp"),
> Â Â Â Â Â Â Â Â Â Â Â Âarray("Wr", "Wn", "Wb", "Wq", "Wk", "Wb", "Wn",
> "Wr"));
>
> $_SESSION['results'] = $results;
> Â Â Â Âfor($i = 0; $i <8; $i++)
> Â Â Â Â{
> Â Â Â Â Â Â Â Âfor ($j = 0; $j < 8; $j++)
> Â Â Â Â Â Â Â Â Â Â Â Âprintf("%s ", $results[$i][$j]);
> Â Â Â Â Â Â Â Âprintf("<br />");
> Â Â Â Â}
>
> $_SESSION[flag] = $flag;
>
> <snip>
>
> $board = array Â//Correlation of input array [chessboard] with internal
> array [results]
> (
> Â Â Â Â Â Â Â Â"a8" => $results[0][0],
> Â Â Â Â Â Â Â Â"b8" => $results[0][1],
> Â Â Â Â Â Â Â Â"c8" => $results[0][2],
> Â Â Â Â Â Â Â Â"d8" => $results[0][3],
> Â Â Â Â Â Â Â Â"e8" => $results[0][4],
> Â Â Â Â Â Â Â Â"f8" => $results[0][5],
> Â Â Â Â Â Â Â Â"g8" => $results[0][6],
> Â Â Â Â Â Â Â Â"h8" => $results[0][7],
> Â Â Â Â Â Â Â Â"a7" => $results[1][0],
> Â Â Â Â Â Â Â Â"b7" => $results[1][1],
> Â Â Â Â Â Â Â Â"c7" => $results[1][2],
> Â Â Â Â Â Â Â Â"d7" => $results[1][3],
> Â Â Â Â Â Â Â Â"e7" => $results[1][4],
> Â Â Â Â Â Â Â Â"f7" => $results[1][5],
> Â Â Â Â Â Â Â Â"g7" => $results[1][6],
> Â Â Â Â Â Â Â Â"h7" => $results[1][7],
> Â Â Â Â Â Â Â Â"a6" => $results[2][0],
> Â Â Â Â Â Â Â Â"b6" => $results[2][1],
> Â Â Â Â Â Â Â Â"c6" => $results[2][2],
> Â Â Â Â Â Â Â Â"d6" => $results[2][3],
> Â Â Â Â Â Â Â Â"e6" => $results[2][4],
> Â Â Â Â Â Â Â Â"f6" => $results[2][5],
> Â Â Â Â Â Â Â Â"g6" => $results[2][6],
> Â Â Â Â Â Â Â Â"h6" => $results[2][7],
> Â Â Â Â Â Â Â Â"a5" => $results[3][0],
> Â Â Â Â Â Â Â Â"b5" => $results[3][1],
> Â Â Â Â Â Â Â Â"c5" => $results[3][2],
> Â Â Â Â Â Â Â Â"d5" => $results[3][3],
> Â Â Â Â Â Â Â Â"e5" => $results[3][4],
> Â Â Â Â Â Â Â Â"f5" => $results[3][5],
> Â Â Â Â Â Â Â Â"g5" => $results[3][6],
> Â Â Â Â Â Â Â Â"h5" => $results[3][7],
> Â Â Â Â Â Â Â Â"a4" => $results[4][0],
> Â Â Â Â Â Â Â Â"b4" => $results[4][1],
> Â Â Â Â Â Â Â Â"c4" => $results[4][2],
> Â Â Â Â Â Â Â Â"d4" => $results[4][3],
> Â Â Â Â Â Â Â Â"e4" => $results[4][4],
> Â Â Â Â Â Â Â Â"f4" => $results[4][5],
> Â Â Â Â Â Â Â Â"g4" => $results[4][6],
> Â Â Â Â Â Â Â Â"h4" => $results[4][7],
> Â Â Â Â Â Â Â Â"a3" => $results[5][0],
> Â Â Â Â Â Â Â Â"b3" => $results[5][1],
> Â Â Â Â Â Â Â Â"c3" => $results[5][2],
> Â Â Â Â Â Â Â Â"d3" => $results[5][3],
> Â Â Â Â Â Â Â Â"e3" => $results[5][4],
> Â Â Â Â Â Â Â Â"f3" => $results[5][5],
> Â Â Â Â Â Â Â Â"g3" => $results[5][6],
> Â Â Â Â Â Â Â Â"h3" => $results[5][7],
> Â Â Â Â Â Â Â Â"a2" => $results[6][0],
> Â Â Â Â Â Â Â Â"b2" => $results[6][1],
> Â Â Â Â Â Â Â Â"c2" => $results[6][2],
> Â Â Â Â Â Â Â Â"d2" => $results[6][3],
> Â Â Â Â Â Â Â Â"e2" => $results[6][4],
> Â Â Â Â Â Â Â Â"f2" => $results[6][5],
> Â Â Â Â Â Â Â Â"g2" => $results[6][6],
> Â Â Â Â Â Â Â Â"h2" => $results[6][7],
> Â Â Â Â Â Â Â Â"a1" => $results[7][0],
> Â Â Â Â Â Â Â Â"b1" => $results[7][1],
> Â Â Â Â Â Â Â Â"c1" => $results[7][2],
> Â Â Â Â Â Â Â Â"d1" => $results[7][3],
> Â Â Â Â Â Â Â Â"e1" => $results[7][4],
> Â Â Â Â Â Â Â Â"f1" => $results[7][5],
> Â Â Â Â Â Â Â Â"g1" => $results[7][6],
> Â Â Â Â Â Â Â Â"h1" => $results[7][7],
> Â Â Â Â);
>
>
> $board2 = array Â//Correlation of input array [chessboard] with internal
> array [results]
> (
> Â Â Â Â Â Â Â Â"a8" => "[0][0]",
> Â Â Â Â Â Â Â Â"b8" => "[0][1]",
> Â Â Â Â Â Â Â Â"c8" => "[0][2]",
> Â Â Â Â Â Â Â Â"d8" => "[0][3]",
> Â Â Â Â Â Â Â Â"e8" => "[0][4]",
> Â Â Â Â Â Â Â Â"f8" => "[0][5]",
> Â Â Â Â Â Â Â Â"g8" => "[0][6]",
> Â Â Â Â Â Â Â Â"h8" => "[0][7]",
> Â Â Â Â Â Â Â Â"a7" => "[1][0]",
> Â Â Â Â Â Â Â Â"b7" => "[1][1]",
> Â Â Â Â Â Â Â Â"c7" => "[1][2]",
> Â Â Â Â Â Â Â Â"d7" => "[1][3]",
> Â Â Â Â Â Â Â Â"e7" => "[1][4]",
> Â Â Â Â Â Â Â Â"f7" => "[1][5]",
> Â Â Â Â Â Â Â Â"g7" => "[1][6]",
> Â Â Â Â Â Â Â Â"h7" => "[1][7]",
> Â Â Â Â Â Â Â Â"a6" => "[2][0]",
> Â Â Â Â Â Â Â Â"b6" => "[2][1]",
> Â Â Â Â Â Â Â Â"c6" => "[2][2]",
> Â Â Â Â Â Â Â Â"d6" => "[2][3]",
> Â Â Â Â Â Â Â Â"e6" => "[2][4]",
> Â Â Â Â Â Â Â Â"f6" => "[2][5]",
> Â Â Â Â Â Â Â Â"g6" => "[2][6]",
> Â Â Â Â Â Â Â Â"h6" => "[2][7]",
> Â Â Â Â Â Â Â Â"a5" => "[3][0]",
> Â Â Â Â Â Â Â Â"b5" => "[3][1]",
> Â Â Â Â Â Â Â Â"c5" => "[3][2]",
> Â Â Â Â Â Â Â Â"d5" => "[3][3]",
> Â Â Â Â Â Â Â Â"e5" => "[3][4]",
> Â Â Â Â Â Â Â Â"f5" => "[3][5]",
> Â Â Â Â Â Â Â Â"g5" => "[3][6]",
> Â Â Â Â Â Â Â Â"h5" => "[3][7]",
> Â Â Â Â Â Â Â Â"a4" => "[4][0]",
> Â Â Â Â Â Â Â Â"b4" => "[4][1]",
> Â Â Â Â Â Â Â Â"c4" => "[4][2]",
> Â Â Â Â Â Â Â Â"d4" => "[4][3]",
> Â Â Â Â Â Â Â Â"e4" => "[4][4]",
> Â Â Â Â Â Â Â Â"f4" => "[4][5]",
> Â Â Â Â Â Â Â Â"g4" => "[4][6]",
> Â Â Â Â Â Â Â Â"h4" => "[4][7]",
> Â Â Â Â Â Â Â Â"a3" => "[5][0]",
> Â Â Â Â Â Â Â Â"b3" => "[5][1]",
> Â Â Â Â Â Â Â Â"c3" => "[5][2]",
> Â Â Â Â Â Â Â Â"d3" => "[5][3]",
> Â Â Â Â Â Â Â Â"e3" => "[5][4]",
> Â Â Â Â Â Â Â Â"f3" => "[5][5]",
> Â Â Â Â Â Â Â Â"g3" => "[5][6]",
> Â Â Â Â Â Â Â Â"h3" => "[5][7]",
> Â Â Â Â Â Â Â Â"a2" => "[6][0]",
> Â Â Â Â Â Â Â Â"b2" => "[6][1]",
> Â Â Â Â Â Â Â Â"c2" => "[6][2]",
> Â Â Â Â Â Â Â Â"d2" => "[6][3]",
> Â Â Â Â Â Â Â Â"e2" => "[6][4]",
> Â Â Â Â Â Â Â Â"f2" => "[6][5]",
> Â Â Â Â Â Â Â Â"g2" => "[6][6]",
> Â Â Â Â Â Â Â Â"h2" => "[6][7]",
> Â Â Â Â Â Â Â Â"a1" => "[7][0]",
> Â Â Â Â Â Â Â Â"b1" => "[7][1]",
> Â Â Â Â Â Â Â Â"c1" => "[7][2]",
> Â Â Â Â Â Â Â Â"d1" => "[7][3]",
> Â Â Â Â Â Â Â Â"e1" => "[7][4]",
> Â Â Â Â Â Â Â Â"f1" => "[7][5]",
> Â Â Â Â Â Â Â Â"g1" => "[7][6]",
> Â Â Â Â Â Â Â Â"h1" => "[7][7]",
> Â Â Â Â);
> Â Â Â Â$results = $_SESSION['results'];
>
> Â Â Â Â$a = "$";
> Â Â Â Â$a .="results";
> Â Â Â Â$a .= "$board2[$value_from]";
>
> Â Â Â Â$b = "$";
> Â Â Â Â$b .="results";
> Â Â Â Â$b .= "$board2[$value_to]";
>
> Â Â Â Â$bb = $board[$value_to];
> Â Â Â Â$aa = $board[$value_from];
>
> Â Â Â Â$b = $aa;
> Â Â Â Â$a = '';
> ========
> I am not able to assign the value Wp to $b which is $results[2][4]. $a,
> which is $results[6][4] should be empty.
>
> Help and advice, please.
>
> Ethan
>
> MySQL 5.1 ÂPHP 5.3.3-6 ÂLinux [Debian (sid)]
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

You are suppressing errors (at least based upon the code you've supplied).

Change ...

error_reporting(1); // Will only report E_ERROR - Fatal run-time
errors. These indicate errors that can not be recovered from, such as
a memory allocation problem. Execution of the script is halted.

to

error_reporting(-1); // Shows everything. The code you've supplied is
missing the values for the $value_from and $value_to.



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux