我有以下代码:
$page=3;
$i=1;
while($i<=$pages) {
$urls .= "'"."http://twitter.com/favorites.xml?page=" . $i ."',";
$i++;
}
Run Code Online (Sandbox Code Playgroud)
我需要创建的是这个数组:
$data = array('http://twitter.com/favorites.xml?page=1','http://twitter.com/favorites.xml?page=2','http://twitter.com/favorites.xml?page=3');
Run Code Online (Sandbox Code Playgroud)
如何从while循环中生成数组?
$urls = array();
for ($x = 1; $x <= 3; $x++) {
$urls[] = "http://twitter.com/favorites.xml?page=$x";
}
Run Code Online (Sandbox Code Playgroud)
.用于连接字符串.
[]用于访问数组.
[] =将值推送到数组的末尾(自动在数组中创建一个新元素并分配给它).