Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8980367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:04:19+00:00 2026-06-15T20:04:19+00:00

I have the following PHP array structure: $set = array(); $set[] = array(‘firstname’=>’firstname 1’,

  • 0

I have the following PHP array structure:

$set = array();
$set[] = array('firstname'=>'firstname 1',
           'lastname'=>'lastname 1',
            "bio"=>array('paragraph 1 of the bio, 'paragraph 2 of the bio','paragraph 3 of the bio'),
           );

I then access the array with the following:

  <?php $counter = 0;
  while ($counter < 1) :  //1 for now
  $item = $set[$counter]?>  

    <h1><?php echo $item['firstname'] ?></h1>
    <h1><?php echo $item['lastname'] ?></h1>

  <?php endwhile; ?>

I’m uncertain how I can loop through the “bio” part of the array and echo each paragraph.

So as a final output, I should have two h1s (first and last name) and three paragraphs (the bio).

How can I go about doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:04:20+00:00Added an answer on June 15, 2026 at 8:04 pm

    You don’t need to use a manual counter, you can use foreach. It’s generally the easiest way and prevents off-by-one errors.

    Then you need a second inner loop to loop through the bio.

    <?php foreach ($set as $item): ?>  
        <h1><?php echo $item['firstname'] ?></h1>
        <h1><?php echo $item['lastname'] ?></h1>
        <?php foreach ($item['bio'] as $bio): ?>
            <p><?php echo $bio; ?></p>
        <?php endforeach; ?>
    <?php endforeach; ?>
    

    On a related note; you probably want to look into escaping your output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following php loop that takes an array that contains a set
I have a PHP multidimensional associative array with the following structure: Fields: TYPE -
I have the following link structure for my portfolio: <?php echo $this->Html->link($post['Portfolio']['title'], array('controller' =>
I have the following serialized PHP array stored in a mySQL database: a:2:{i:2070;s:4:0.00;i:1901;s:4:1.00;} Now,
I have the following php code that gets a serialized array from a mysql
I have the following case in php $one = array('one' => 1, 2 =>
I have the following code in config: <?php return array( 'di' => array( 'instance'
I am using the MongoDB PHP Library and have the following query array Array
I have the following code: <?php function foo($bar) { global $products; //$products = array();
I have the following array structure in MySQL. There could be no items or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.