user760946
user760946

Reputation: 95

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';
$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

Answers (3)

martynthewolf
martynthewolf

Reputation: 1708

Like this

$char = 'A';
$window=array();

for($i=0;$i<8;$i++)
{
   $window[] = $char."1," . $char++ . "8";

}

Upvotes: 1

XMen
XMen

Reputation: 30238

Use : array_push

https://www.php.net/manual/en/function.array-push.php

Upvotes: 0

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385104

Use $array[] = newvalue syntax:

$char   = 'A';
$window = Array();

for ($i=0;$i<8;$i++) {
   $window[] = $char . "1" . $char . "8";
   $char++;
}

Upvotes: 3

Related Questions