开发者

Store values in an array in php

开发者 https://www.devze.com 2023-03-08 11:25 出处:网络
I want to store values like A1,A8, B1,B8, C1,C8.. and till H1,H8 in an array. $char = \'A\'开发者_如何学JAVA;

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

0

精彩评论

暂无评论...
验证码 换一张
取 消