Store values in an array in php
I want to store values like A1,A8
, B1,B8
, C1,C8
.. and till H1,H8
in an array.
$char = 'A'开发者_如何学JAVA;
$window=array();
for($i=0;$i<8;$i++)
{
echo $char."1";
echo $char++."8";
}
This for loop prints the data A1,A8 TO H1,H8.
I want to store these values in array window
.
How can I do this?
Use $array[] = newvalue
syntax:
$char = 'A';
$window = Array();
for ($i=0;$i<8;$i++) {
$window[] = $char . "1" . $char . "8";
$char++;
}
Like this
$char = 'A';
$window=array();
for($i=0;$i<8;$i++)
{
$window[] = $char."1," . $char++ . "8";
}
Use : array_push
http://in3.php.net/manual/en/function.array-push.php
精彩评论