摘要: 很多时候我们会看到这样的代码(出自 CI 框架源码):1$class=& load_class('a','b');我们都知道其中的'&'是指引用,但是它的作用是什么呢?它能够解决什么样的问题呢?带着这些问题,我们开始了解下“引用返回”。引用返回手册里是这么写的:引用返回用在当想用函数找到引用应该被绑定在哪一个变量上面时。不要用返回引用来增加性能,引擎足够聪明来自己进行优化。仅在有合理的技术原因时才返回引用!要返回引用,使用此语法:01value;07}08}0910$obj=newfoo;11// $myValue is a re 阅读全文
posted @ 2013-08-01 16:00 幻星宇 阅读(244) 评论(0) 推荐(0) 编辑
摘要: 从一道面试题开始在开始本节内容前,我们先来看看一道还算比较常见的PHP面试题:1$arr=array('1','2','3');23foreach($arras&$v){4}56foreach($arras$v){7}89var_dump($arr);猜一下,运行的结果会是什么呢?熟悉PHP的同学可能已经知道结果了:1array20 => string'1'(length=1)31 => string'2'(length=1)42 => &string'2'(len 阅读全文
posted @ 2013-08-01 15:34 幻星宇 阅读(441) 评论(0) 推荐(0) 编辑
摘要: $val) { if (isset($array_2[$val])) { unset($array_1[$key]); } } return $array_1;}function runtime($mode = 0) { static $t; if (!$mode) { $t = microtime(); return; } $t1 = microtime(); list($m0, $s0) = explode(" ", $t); list($m1, $s1) = explode(" ", $t1); return sprintf("%.3f& 阅读全文
posted @ 2013-08-01 15:19 幻星宇 阅读(679) 评论(0) 推荐(0) 编辑
摘要: $data) { $refer[$data[$pk]] = &$list[$key]; } foreach ($list as $key => $data) { //判断是否存在parent $parantId = $data[$pid]; if ($root == $parantId) { $tree[] = &$list[$key]; } else { if (isset($refer[$parantId])) { $parent = &$refer[$parantId]; $parent[$child][] = &$list[$k... 阅读全文
posted @ 2013-08-01 11:34 幻星宇 阅读(2351) 评论(0) 推荐(0) 编辑
摘要: $item ) { if ($item [$pid]) { if (! isset ( $t [$item [$pid]] ['parent'] [$item [$pid]] )) $t [$item [$id]] ['parent'] [$item [$pid]] = & $t [$item [$pid]]; } } return $t;}/** * * 创建子节点树形数组 * 参数 * $ar 数组,邻接列表方式组织的数据 * $id 数组中作为主键的下标或关联键名 * $pid * 数组中作为父键的下标或关联键名 * 返回 多维数组 * */fun 阅读全文
posted @ 2013-08-01 10:06 幻星宇 阅读(392) 评论(0) 推荐(0) 编辑
摘要: array('id'=>1,'pid'=>0,'name'=>'News_1'),2=>array('id'=>2,'pid'=>1,'name'=>'News_12'),7=>array('id'=>7,'pid'=>1,'name'=>'News_17'),3=>array('id'=>3,'pid& 阅读全文
posted @ 2013-08-01 09:55 幻星宇 阅读(372) 评论(0) 推荐(0) 编辑
摘要: // @param array $list 查询结果//@param string $field 排序的字段名//@param array $sortby 排序类型//asc正向排序 desc逆向排序 nat自然排序function list_sort_by($list,$field, $sortby='asc') {if(is_array($list)){$refer = $resultSet = array();foreach ($list as $i => $data){$refer[$i] = &$data[$field];switch ($sortby) 阅读全文
posted @ 2013-08-01 09:48 幻星宇 阅读(232) 评论(0) 推荐(0) 编辑