Reputation: 95
I want to store values like A1,A8
, B1,B8
, C1,C8
.. and till H1,H8
in an array.
$char = 'A';
$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?
Upvotes: 0
Views: 7130
Reputation: 1708
Like this
$char = 'A';
$window=array();
for($i=0;$i<8;$i++)
{
$window[] = $char."1," . $char++ . "8";
}
Upvotes: 1
Reputation: 30238
Use : array_push
https://www.php.net/manual/en/function.array-push.php
Upvotes: 0
Reputation: 385104
Use $array[] = newvalue
syntax:
$char = 'A';
$window = Array();
for ($i=0;$i<8;$i++) {
$window[] = $char . "1" . $char . "8";
$char++;
}
Upvotes: 3