PHP 的引用变量问题
$xml = '../data/news.xml' ;
$qp = qp($xml, 'news_root')->children();
$arrData = array() ;
$i = 0 ;
foreach( $qp as $child )
{
print_r( $arrData );
echo "<br/>hi<br/>";
unset($arrSub);
$arrSub = array() ;
array_push( $arrData , &$arrSub );
print_r( $arrData );
echo "<br/>";
// $arrData[] = &$arrSub;
$child = $child->children() ;
foreach( $child as $item )
{
$arrSub[ $item->tag() ] = $item->text();
}
print_r( $arrData );
echo"<br/>";
}
上面的代码,注意 unset($arrSub) 这句.
我的本意是 $arrData 解析出xml的2层内容.
我用array_push压入一个引用的数组 arrSub ,
然后操作arrSub,等于修改arrData.
但是,这其实是有问题的.
显示arrData最后的内容全是最后一条xml内容的复制. (我的xml最后是空项,所以arrData是:[ [],[] ] ,而不是正确的: [ [data1,data2] , [] ]
当我用引用把arrSub压入arrData后,
一个循环过后,又遇到语句 $arrSub = array() ; 这就有问题了,这句话执行后, arrData里面的一个也变成了空的array.
所以必须解除引用 unset( $arrSub ) 就能解决问题.
相关文档:
how to install apache, PHP and MySQL on Linux
This tutorial explains the installation of Apache web server, bundled with PHP and MySQL server on a Linux machine. The tutorial is primarily for SuSE 9.2, 9.3, 10.0 & 10.1 operating systems, but most of the steps ought to be valid for all Linux-lik ......
how to install apache, PHP and MySQL on Linux
This tutorial explains the installation of Apache web server, bundled
with PHP and MySQL server on a Linux machine. The tutorial is primarily for SuSE
9.2, 9.3, 10.0 & 10.1, but most of the steps ought to be valid for all
Linux-like operating ......
how to install apache, PHP and MySQL on Linux
This tutorial explains the installation of Apache web server, bundled
with PHP and MySQL server on a Linux machine. The tutorial is primarily for SuSE
9.2, 9.3, 10.0 & 10.1, but most of the steps ought to be valid for all
Linux-like operating ......
$_FILES['myFile']['name'] 客户端文件的原名称。
$_FILES['myFile']['type'] 文件的 MIME 类型,需要浏览器提供该信息的支持,例如"image/gif"。
$_FILES['myFile']['size'] 已上传文件的大小,单位为字节。
$_FILES['myFile']['tmp_n ......
过年了,也涨了一岁了,感觉没有长进啊!
唉!
年前参加了中国电信的面试。
感觉很一般,连SQL全称是什么都不懂,还好意思自称熟练运用MYSQL,唉!
过完年,要开始为实习而奔波了。
网龙看来是没希望了。
只能进一些比较一般的公司学习学习了。
从今天开始,认真看PHP100的最新几个视频。
开始通读DZ的程序,注解上 ......