
需要准备的材料分别是:电脑、php编辑器、浏览器。
1、首先,打开php编辑器,新建php文件,例如:indexphp,并定义一个数组。
2、在indexphp中,输入代码:echo $a[mt_rand(0, count($a) - 1)];。
3、浏览器运行indexphp页面,此时随机打印出了数组中的值。
4、浏览器按F5刷新,发现确实是随机的。
是的,3L的代码对于特定的项目确实可以,但是楼主的项目位置,因此我们要给出一般性的思路而不是特定的代码。
首先你应该判断当前页面,如果当前浏览的页面是某个栏目页面,则设置为高亮,PHP可以获取当前脚本的名称$_SERVER['SCRIPT_NAME'],注意它前面是有一个斜杠的,所以你在判断的时候要处理
session_start();
$image=imagecreatetruecolor(200, 60);//创建画布
$color = imagecolorallocate($image, mt_rand(157,255), mt_rand(157,255), mt_rand(157,255));//随机颜色
//$color=imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $color);//填充颜色
//中文验证码
$fontface="simheittf";//确保相同目录下有该字体
$strdb=array('好','多','人','在','学','习');
for ($i=0;$i<4;$i++){
$fontsizecolor=imagecolorallocate($image, mt_rand(0, 150), mt_rand(0, 150), mt_rand(0, 150));
$codex=iconv("GB2312","UTF-8",$strdb[mt_rand(0,5)]);//iconv不能转数组 取任意下标
imagettftext($image, mt_rand(20, 24), mt_rand(-30, 30), (40$i+20), mt_rand(30, 35), $fontsizecolor, $fontface, $codex);//如果用$code的话 就生成 1+2+3+4 是个汉字的验证码了
}
//干扰点
for ($i=0;$i<200;$i++){
$pointcolor=imagecolorallocate($image, mt_rand(50, 200), mt_rand(50, 200), mt_rand(50, 200));
imagesetpixel($image, mt_rand(1, 100), mt_rand(1,20), $pointcolor); //雪花
}
//干扰线
for ($i=0;$i<3;$i++){
$linecolor=imagecolorallocate($image, mt_rand(50, 200), mt_rand(50, 200), mt_rand(50, 200));
imageline($image, mt_rand(1, 99), mt_rand(1, 99), mt_rand(1, 99), mt_rand(1, 99), $linecolor);
}
ob_clean();
header("Content-type:image/png");
imagepng($image);
imagedestroy($image);
以上就是关于PHP怎么随机获取数组里面的值全部的内容,包括:PHP怎么随机获取数组里面的值、php怎么随机高亮一个数组、php中文验证码无法显示等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)