Printing an array in php -


Now I understand that you can not use Echo to print the content of an array and you can use foreach It has to be used, but for some reason it does not work. Any ideas?

  $ rows = $ stmt-> Fatch ALL (); Forex currency ($ line as the $ key = & gt; $ line) {resonates "My value is $ line in the $ key"; }}   

Output:

  In 0, my value is ArrayMy's value at ArrayMy's value of 2 is Array   < / Div> 

It appears that you have used fetchAll from the PDO.

This method returns an array of array (rows) in the internal arrays, column_name = & gt; For example, if you have retrieved columns 'first name' and 'last name' for the value element, then these values ​​will be for the first value $ rows [0] ['first name'] < / Code> and $ rows [0] ['last name'] respectivelly

The proper way to do this would be:

  $ rows = $ stmt-> Fatch ALL (); Forex currency ($ line as $ key = & gt; $ line) {foreach ($ column $ $ column = & gt; $ value) {resonates "My $ column value is $ value for row $ key \ n "; }}   

Fury: See bracket alignment, this is not correct, but this makes the code more readable :)

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -