欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php遍歷類中包含的所有元素的方法

 更新時(shí)間:2015年05月12日 09:41:08   作者:企鵝不笨  
這篇文章主要介紹了php遍歷類中包含的所有元素的方法,涉及php中g(shù)etConstants方法及數(shù)組操作的相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了php遍歷類中包含的所有元素的方法。分享給大家供大家參考。具體分析如下:

這里可獲得php類包含的所有元素以key-value的形式輸出

class MyTestClass{
  const TESTVAR1 = 1001;
  const TESTVAR2 = 1002;
  const TESTSTR1 = 'hello';
}
$rc = new ReflectionClass('MyTestClass');
$v = $rc->getConstants(); 
asort($v);// sort by value
//ksort($v);// sort by key
foreach ( $v as $name => $value){
  echo "$name => $value\n";
}

運(yùn)行結(jié)果如下:

TESTSTR1 => hello
TESTVAR1 => 1001
TESTVAR2 => 1002

希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論