全球主机交流论坛

标题: 求php大佬帮忙看一下,(已解决) [打印本页]

作者: doing    时间: 2018-11-22 18:13
标题: 求php大佬帮忙看一下,(已解决)
本帖最后由 doing 于 2018-11-22 18:33 编辑

for($j=0;$j<200;$j++)
{
        $array = array('北京','天津','上海','重庆');
        $length = count($array);
        $random = mt_rand(0,$length-1);

$result = $array[$random];

}



最后
echo  $result;  可结果只有一个,我想有200个结果。请大佬帮改一下,谢谢了。
现在也不让悬赏问问题,很难受

======================

已解决。我试了几位大佬的代码都可以。非常感谢
作者: gdtv    时间: 2018-11-22 18:15
  1. for($j=0;$j<200;$j++)
  2. {
  3.         $array = array('北京','天津','上海','重庆');
  4.         $length = count($array);
  5.         $random = mt_rand(0,$length-1);

  6. $result[] = $array[$random];

  7. }

  8. print_r($result);
复制代码

作者: ǿ    时间: 2018-11-22 18:16
提示: 作者被禁止或删除 内容自动屏蔽
作者: yemingtu    时间: 2018-11-22 18:17
  1. $result = array();
  2. for($j=0;$j<200;$j++)
  3. {
  4.     $array = array('北京','天津','上海','重庆');
  5.     $length = count($array);
  6.     $random = mt_rand(0,$length-1);

  7.     $result[] = $array[$random];
  8. }
复制代码

作者: imdong    时间: 2018-11-22 18:22
三楼正解
作者: diaoye73    时间: 2018-11-22 18:26
php数组追加数据的方式 $result[] =  $xxx;
作者: solomon    时间: 2018-11-22 18:40
太简单了,以后再来麻烦我们大佬请提高下难度。
作者: 醉里耍大刀    时间: 2018-11-22 18:49
三楼正解,不要在循环里面赋值和计算




欢迎光临 全球主机交流论坛 (https://loc.wget.at/) Powered by Discuz! X3.4