php 删除数据键值代码
/**
* 删除key为指定的key里的值
* @param array $array 操作的数组
* @param string $key 键值可以是数组
* @return void
*/
public static function delete(&$array, $key) {
if (!is_array($key)) {
$key = array($key);
}
foreach ($key as $k) {
unset($array[$k]);
}
$array = array_values($array);
}
php 对数组排序实例代码
* 对数组排序
* @param array $array 操作的数组
* @param string $type key按键排序,value按值排序
* @param string $field 字段名
* @param string $order 排序方式asc顺序desc逆序
* @return void
*/
public static function sort(&$array, $type = 'value', $field = NULL, $order = 'asc') {
if ($field) {
foreach ($array as $key => $value) {
$temp[$key] = $value[$field];
}
if ($order=='asc') {
asort($temp);
} else {
arsort($temp);
}
$newarray = array();
foreach ($temp as $key => $value) {
$newarray[] = $array[$key];
}
$array = $newarray;
} else {
if ($type=='key') {
if ($order=='asc') {
ksort($array);
} else {
krsort($array);
}
} else {
if ($order=='asc') {
asort($array);
} else {
arsort($array);
}
}
}
}
php+js 实例入门教程网上很多,我们这款是边学边来看实例哦,告诉你快速入门ajax哦。
function checkfortasks (thedate, e){
//找到页面中taskbox对应<div>设置为可见
theObject = document.getElementById("taskbox");
theObject.style.visibility = "visible";
//初始化taskbox位置
var posx = 0;
var posy = 0;
//定位taskbox位置为鼠标位置
posx = e.clientX + document.body.scrollLeft;
posy = e.clientY + document.body.scrollTop;
theObject.style.left = posx + "px";
theObject.style.top = posy + "px";
//设置PHP请求页面
serverPage = "taskchecker.php?thedate=" + thedate;
//设置PHP返回数据替换位置
objID = "taskbox";
var obj = document.getElementById(objID);
//发送请求并加载返回数据
xmlhttp.open("GET", serverPage);
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}
function autocomplete (thevalue, e){
//定位页面中autocompletediv(显示检索姓名的标签)的<div>位置
theObject = document.getElementById("autocompletediv");
//设置为可见
theObject.style.visibility = "visible";
theObject.style.width = "152px";
//设置检索标签位置
var posx = 0;
var posy = 0;
posx = (findPosX (document.getElementById("yourname")) + 1);
posy = (findPosY (document.getElementById("yourname")) + 23);
theObject.style.left = posx + "px";
theObject.style.top = posy + "px";
//设定事件为键盘录入
var theextrachar = e.which;
if (theextrachar == undefined){
theextrachar = e.keyCode;
}
//设定加载检索名单位置
var objID = "autocompletediv";
//设定PHP请求页面,并将用户输入的姓名传值过去(同时考虑到Backspace作用)
if (theextrachar == 8){
if (thevalue.length == 1){
var serverPage = "autocomp.php";
}
else{
var serverPage = "autocomp.php" + "?sstring=" + thevalue.substr(0, (thevalue.length -1));
}
}
else{
var serverPage = "autocomp.php" + "?sstring=" + thevalue + String.fromCharCode(theextrachar);
}
//发送请求并加载返回数据
var obj = document.getElementById(objID);
xmlhttp.open("GET", serverPage);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}
php 删除文件与目录代码
function del($name) {
if (!is_dir($name)) {
return @unlink($name);
} else {
$dir = opendir($name);
while( $file = readdir( $dir ) ) {
if (($file=='.')||($file=='..')) continue;
if (is_dir($name.'/'.$file)) $this->del($name.'/'.$file);
else echo basename($file), @unlink($name.'/'.$file) ? ' Success!' : ' False.', '<br />';
}
closedir($dir);
}
return @rmdir($name);
}
php 复制文件
function copy($from, $to) {
if ($this->abspath($to)=="/") $to=$this->basedir;
if ($this->dirname($from) == $this->dirname($to)) $to = $this->dirname($to).'/复件'.basename($from);
if (!is_dir($from)) {
return @copy($from, $to);
} else {
if (!is_dir($to)) @mkdir($to);
$path = opendir($from);
while( $file = readdir( $path ) ) {
if (($file=='.')||($file=='..')) continue;
if (is_dir($from.'/'.$file)) $this->copy($from.'/'.$file, $to.'/'.$file);
else echo basename($file), copy($from.'/'.$file, $to.'/'.$file) ? ' Success!' : ' False.', '<br />';
}
return true;
}
}