How to display PHP array contents in hmtl format? |
How to display PHP array contents in hmtl format? |
Forca |
May 22 2017, 12:01 AM
Post
#1
|
Member Group: Members Posts: 33 Joined: 29-April 16 Member No.: 24,203 |
I have an array of strings in a PHP script. Array has 10 keys. I wish to display contents of each array entry in html format by using embedded html.
Question: how to output a PHP array variable contents so that it can be styled by the applicable CSS styling sheet for the webpage? I considered: <code> <?php if (condition): ?> <p> Message to be displayed in html format since paragraph display governed by associated CSS file. </p> <?php end-condition; ?> </code> So how to get the paragraph contents to be the output of the PHP array variable? Thanks. |
Christian J |
May 22 2017, 09:03 AM
Post
#2
|
. Group: WDG Moderators Posts: 9,661 Joined: 10-August 06 Member No.: 7 |
I have an array of strings in a PHP script. Array has 10 keys. I wish to display contents of each array entry in html format by using embedded html. You might iterate through the array, like this: CODE foreach ($arr as $value) { echo "Value: $value<br />\n"; } or this, if you want to display the $key names as well: CODE foreach ($arr as $key => $value) { echo "Key: $key; Value: $value<br />\n"; } (examples from http://php.net/manual/en/control-structures.foreach.php ). There are several ways to loop/iterate through arrays in PHP, and while the manual isn't very easy to understand there are lots of other sites on the web too. QUOTE Question: how to output a PHP array variable contents so that it can be styled by the applicable CSS styling sheet for the webpage? Not sure I understood this, why not simply make the HTML and CSS selectors match the way you want? |
Lo-Fi Version | Time is now: 27th April 2024 - 09:44 PM |