小编Dav*_*yre的帖子

(PHP)选择三个没有重复值的随机数

我必须从1到3得到三个随机数,结果中没有重复值:
$ total ='3';
$ rand1 = rand(1,$ total);
$ rand2 = rand(1,$ total);
$ rand3 = rand(1,$ total);
结果如下:1.2.3或3.2.1,或2.1.3
请提前帮助我,谢谢

php random

1
推荐指数
1
解决办法
1825
查看次数

将字符串传递给PHP数组

我有这样的字符串列表:

'PYRAMID','htc_europe','htc_pyramid','pyramid','pyramid','HTC','1.11.401.110 CL68035 release-keys','htc_europe/pyramid/pyramid:4.0.3/IML74K/68035.110:user /释放密钥

它看起来像数组的元素,但是当我使用时

<?php
    $string = "'PYRAMID','htc_europe','htc_pyramid','pyramid','pyramid','HTC','1.11.401.110 CL68035 release-keys','htc_europe/pyramid/pyramid:4.0.3/IML74K/68035.110:user/release-keys'";
    $arr = array($string);
    print_r($arr);

 ?>
Run Code Online (Sandbox Code Playgroud)

它不能按我的意愿工作:

数组([0] =>'PYRAMID','htc_europe','htc_pyramid','金字塔','金字塔','HTC','1.11.401.110 CL68035 release-keys','htc_europe/pyramid/pyramid:4.0. 3/IML74K/68035.110:用户/释放密钥)

代替:

数组([0] => PYRAMID,[1] => htc_europe,[2] => htc_pyramid,...

我不想使用explode(),因为我的字符串已经是数组格式,许多字符串都有' , '字符.请帮帮我,谢谢.

php arrays

-1
推荐指数
1
解决办法
55
查看次数

标签 统计

php ×2

arrays ×1

random ×1