The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> How to display PHP array contents in hmtl format?
Forca
post 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.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post May 22 2017, 09:03 AM
Post #2


.
********

Group: WDG Moderators
Posts: 9,628
Joined: 10-August 06
Member No.: 7



QUOTE(Forca @ May 22 2017, 07:01 AM) *

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?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th March 2024 - 01:48 AM