首页 > Web开发 > 详细

php 实现传入参数的传出

时间:2014-12-30 11:21:46      阅读:270      评论:0      收藏:0      [点我收藏+]

 

类似于.net的out功能,php中可以使用&实现

如下示例:

<?php
$x
=2; inOutFunction($x); function inOutFunction(&$x){ $x=3; return ‘a‘; } echo $x; exit();


同样,在递归中可以使用此方法传值:

如下示例遍历文件夹中的文件:

<?php
$dir
=‘/‘; print_r(scanfDir($dir,true,$ret)); function scanfDir($dir = ‘‘, $all = false, &$ret = array()) { $x=‘avc‘; if (false !== ($handle = opendir($dir))) { while (false !== ($file = readdir($handle))) { if (!in_array($file, array(‘.‘, ‘..‘, ‘.git‘, ‘.gitignore‘, ‘.svn‘, ‘.htaccess‘, ‘.buildpath‘, ‘.project‘))) { $cur_path = $dir . ‘/‘ . $file; if (is_dir($cur_path)) { $ret[‘dirs‘][] = $cur_path; $all && scanfDir($cur_path, $all, $ret); } else { $ret [‘files‘] [] = $cur_path; } } } closedir($handle); } return $ret; }

 

php 实现传入参数的传出

原文:http://www.cnblogs.com/Bin-x/p/4193116.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!