创建一个简单的数组

CLi*_*own 3 php arrays

我有以下代码:

$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循环中生成数组?

dec*_*eze 6

$urls = array();
for ($x = 1; $x <= 3; $x++) {
    $urls[] = "http://twitter.com/favorites.xml?page=$x";
}
Run Code Online (Sandbox Code Playgroud)

.用于连接字符串.
[]用于访问数组.
[] =将值推送到数组的末尾(自动在数组中创建一个新元素并分配给它).

  • 我认为你需要$ x里面的字符串,而不是$ i? (2认同)