澳门新葡萄京官网注册‘大公司’的PHP面试题

?phpclassengage{publicfunctiongetArray(){$arr1=array(”0”=array(”fid”=1,”tid”=1,”name”=”Name1”),”1”=array(”fid”=1,”tid”=2,”name”=”Name2”),”2”=array(”fid”=1,”tid”=5,”name”=”Name3”),”3”=array(”fid”=1,”tid”=7,”name”=”Name4”),”4”=array(”fid”=3,”tid”=9,”name”=”Name5”));$arr2=array();foreach($arr1as$key=$value){$arr2[$value[”fid”]][]=array(”tid”=$value[”tid”],”name”=$value[”name”]);}return$arr2;}//print_r($arr2);//$eString=”open_door”;publicfunctiongetString($eString=null){$eString=explode(”_”,$eString);$eString=array_map(ucfirst,$eString);$eString=implode($eString,””);return$eString;}/***冒泡排序*@returnunknown*/publicfunctiongetBubble(){$isOver=false;$bubbleArray=array(10,2,36,14,10,25,23,85,99,45);$bubbleResult=$bubbleArray;do{$bubbleArray=$bubbleResult;$isOver=true;foreach($bubbleArrayas$key=$value){if($value$bubbleResult[澳门新葡萄京官网注册,$key-1]){$bubbleResult[$key]=$bubbleResult[$key-1];$bubbleResult[$key-1]=$value;$isOver=false;}}}while(!$isOver);return$bubbleResult;}}$engage=newengage();print_r($engage-getArray());echo$engage-getString(”make_by_id”);print_r($engage-getBubble());?/pre?php/***第二题正则替换实现.**/functiongetString($eString=null){$eString=preg_replace(array(/(^[a-z]{1}|_[a-z]{1})/e,”/_/”),array(strtoupper(”1”),””),$eString);return$eString;}?<

dump() 把数组以数组格式数组,有益于调试
function dump($vars, $label = ”, $return = false){
if (ini_get(‘html_errors’)) {
$content = “<pre>n”;
if ($label != ”) {
$content .= “<strong>{$label} :</strong>n”;
}
$content .= htmlspecialchars(print_r($vars, true));
$content .= “n</pre>n”;
} else {
$content = $label . ” :n” . print_r($vars, true);
}
if ($return) { return $content; }
echo $content;
return null;
}
array_remove_empty()去除数组中为空的元素
function array_remove_empty(& $arr, $trim = true){
foreach ($arr as $key => $value) {
if (is_array($value)) {
array_remove_empty($arr[$key]);
} else {
$value = trim($value);
if ($value == ”) {
unset($arr[$key]);
} elseif ($trim) {
$arr[$key] = $value;
}
}
}
}
array_chunk() php默认函数 作用是把函数平均分组

发表评论

电子邮件地址不会被公开。 必填项已用*标注