Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:打印来自类的数组_Php_Arrays_Class_Printing - Fatal编程技术网

PHP:打印来自类的数组

PHP:打印来自类的数组,php,arrays,class,printing,Php,Arrays,Class,Printing,我在自学php,我一直在努力表示来自类的数据数组。 下面是Myclass.php: class Myclass { private $iVar1; private $strVar2; public function __construct() { $this->initialize(); } private function initialize(

我在自学php,我一直在努力表示来自类的数据数组。 下面是Myclass.php:

 class Myclass
    {

        private $iVar1;
        private $strVar2;



        public function __construct() 
        {
            $this->initialize();
        }


        private function initialize()
        {
            $this->iVar1 = null;
            $this->strVar2 = null;
        }

        public function getParam1()
        {
            return $this->iVar1;
        }


        public function setParam1($value)
        {
            $this->iVar1 = $value;
        }


        public function getParam2()
        {
            return $this->strVar2;
        }


        public function setParam2($value)
        {
            $this->strVar2 = $value;
        }


    }

    class MyclassDAO
    {

        static public function load($oBD, $idObjet)
        {

            $aryM = MyclassDAO::getAryM($oBD, $idObjet);

            return $aryM[0];
        }

        static public function getAryM($oBD, $omy)
        {
            $aryCollection = array();

                $sSql = 'EXEC MYDB.dbo.SELECT_MYPROCEDURE ';

                if (!is_null($omy->getParam1()))
                {
                    $sSql .=" @param1 = '".$omy->getParam1()."',";  
                }
                if (!is_null($omy->getParam2()))
                {
                    $sSql .=" @param2 = '".$omy->getParam2()."',";   
                }

                //I delete de last ,
                $sSql =  substr($sSql,0,strlen($sSql)-1); 


                        while ($d = $oBD->fArray()) 
                        { 
                            $omy = new GrupoAlumno();
                            $omy->setParam1($d['param1']);
                            $omy->setParam2($d['param2']);
                            $aryCollection[] = $omy;
                        }

            return $aryCollection;
        }



    }
这是我的php文件:

require_once "Myclass.php";
$var1=1;
$var2=’Y’;    
 $om = new Myclass();
            $om->setParam1($var1);
            $om->setParam2($var2);
            $omDAO = new MyclassDAO();
            $ary= $omDAO->load($myObjDB, $om);
// the printing of the info here
类返回的信息具有以下结构:

$ary: array=
0:object(Myclass)=
iVar1:long=113
strVar2:string=SOMEINFO
1: object(Myclass)=
iVar1:long=114
strVar2:string=SOMEINFO2
如何在我的php文件中打印它

非常感谢

只需使用print\r($ary)或var\u dump($ary)

这将打印数组

//将多维数组显示为HTML无序列表。
// Displays a multi-dimensional array as a HTML unordered lists.
function displayTree($array) {
    $newline = "<br>";
    foreach($array as $key => $value) {    //cycle through each item in the array as key >=> value pairs
      if (is_array($value) || is_object($value)) {        
        //if the VALUE is an array, then
        //call it out as such, surround with brackets, and recursively call displayTree.
        $value = "Array()" . $newline . "(<ul>" . displayTree($value) . "</ul>)" . $newline;
      }
      //if value isn't an array, it must be a string. output its' key and value.
      $output .= "[$key] => " . $value . $newline;
    }
    return $output;
}
函数displayTree($array){ $newline=“
”; foreach($array as$key=>$value){//以key>=>值对的形式遍历数组中的每个项 如果(is_数组($value)| is_对象($value)){ //如果该值是数组,则 //这样调用它,用括号括起来,递归地调用displayTree。 $value=“Array()”$newline.(
    ”.displayTree($value)。“
)”$newline; } //若值不是数组,那个么它必须是字符串。输出它的键和值。 $output.=“[$key]=>”$value.$newline; } 返回$output; }

这将帮助您以一种更好、更快的方式完成这项工作,系统负载将较低

,因为这样做$ary只保存一次迭代,而不打印任何内容。。为什么?
// Displays a multi-dimensional array as a HTML unordered lists.
function displayTree($array) {
    $newline = "<br>";
    foreach($array as $key => $value) {    //cycle through each item in the array as key >=> value pairs
      if (is_array($value) || is_object($value)) {        
        //if the VALUE is an array, then
        //call it out as such, surround with brackets, and recursively call displayTree.
        $value = "Array()" . $newline . "(<ul>" . displayTree($value) . "</ul>)" . $newline;
      }
      //if value isn't an array, it must be a string. output its' key and value.
      $output .= "[$key] => " . $value . $newline;
    }
    return $output;
}