中级php测试
时间:2006-05-30 来源:jingzhi
* @return array
*/
function assoc_unique(& $arr,$group_keys)
{
if (is_array($arr)) {
if (!is_array ($group_keys)) $group_keys = array ($name);
$existing_sub_keys = array ();
$output = array ();
foreach ($arr as $key => $sub_array){
$puffer = NULL;
#group keys
foreach ($group_keys as $group_key){
$puffer .= $sub_array[$group_key];
}
$puffer = serialize ($puffer);
if (!in_array ($puffer, $existing_sub_keys)){
$existing_sub_keys[$key] = $puffer;
$output[$key] = $sub_array;
}
else{
unset($arr[$key]);
}
}
return $output;
}else{
return false;
}
}
//测试
$aa = array(
array('id' => 123, 'name' => '张三'),
array('id' => 123, 'name' => '李四'),
array('id' => 124, 'name' => '王五'),
array('id' => 125, 'name' => '赵六'),
array('id' => 126, 'name' => '赵六'),
array('id' => 123, 'name' => '赵六'),
array('id' => 126, 'name' => '赵六')
);
//$output = assoc_unique($aa,'id');
//print_r($output);
//print_r($aa);
//$output = assoc_unique($aa,'name');
//print_r($output);
//print_r($aa);
//一句正则
preg_match_all ("/[\[\"\'\{\(\}]/U",
"[May/12/2006 11:12:13] (GET [/index.html] HTTP/1.0) 'sdfsdfdsfds' \"fsddsfds\" {FSDDFSFSDFDS}",$out, PREG_PATTERN_ORDER);
print_r($out);
//验证码生成,防止orc
#----------------------------------------------
# 文 件: verify.php
# 功 能: 认证码显示
# Liu21st,[email protected]
# 最后修改: 2004-05-07 10:57:30 Liu21st
#----------------------------------------------
$type=($_GET['t'])?($_GET['t']):'gif';
$width=($_GET['w'])?($_GET['w']):54;
$height=($_GET['h'])?($_GET['h']):22;
session_start();
Header("Content-type: image/".$type);
srand((double)microtime()*1000000);
$randval = sprintf("%04d", rand(0,9999));
session_register('session_verify');
if ( is_array($_SESSION) ) {
$_SESSION['session_verify'] = $randval;
$session_verify =$_SESSION['session_verify'];
}
else {
$session_verify = $randval;
}
if ( $type!='gif' && function_exists('imagecreatetruecolor')) {
$im = @imagecreatetruecolor($width,$height);
}else {
$im = @imagecreate($width,$height);
}
$r = Array(225,255,255,223);
$g = Array(225,236,237,255);
$b = Array(225,236,166,125);
$key = rand(0,3);
$backColor = ImageColorAllocate($im, $r[$key],$g[$key],$b[$key]);//背景色(随机)
$borderColor = ImageColorAllocate($im, 0, 0, 0);//边框色
$pointColor = ImageColorAllocate($im, 0, 255, 255);//点颜色
@imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);
@imagerectangle($im, 0, 0, $width-1, $height-1, $borderColor);
$stringColor = ImageColorAllocate($im, 255,51,153);
for($i=0;$i
相关阅读 更多 +