php - show all columns in zend framework -


here zend phtml file :

<?php  foreach ($this ->books $key =>$value) {     echo $value->title.'by'.$value->author.'<br>'; }  

and result :
first titleby first book
second titleby second book
third titleby third book
fourth titleby fourth book


"title" , "author" 2 columns of table,my table has 4 columns, want iterate on columns without knowing names inside table.

maybe can use refection.

try this:

class a{     public $prop1 = null;     public $prop2 = null;     public $prop3 = null;     public $prop4 = null; }  $a1 = new a(); $a1->prop1 = "prop11"; $a1->prop2 = "prop12"; $a1->prop3 = "prop13"; $a1->prop4 = "prop14";   $a2 = new a(); $a2->prop1 = "prop21"; $a2->prop2 = "prop22"; $a2->prop3 = "prop23"; $a2->prop4 = "prop24";  $tab = array($a1,$a2);  foreach($tab $key => $value){     $reflector = new reflectionclass(get_class($value));      $properties = $reflector->getproperties(reflectionproperty::is_public);     $var_out = "";     foreach($properties $property){         $var_out .= ", " . $property->getname() . " = ". $value->{$property->getname()};     }     echo trim($var_out, ", ") . "<br>"; } 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -