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

  • Home
  • SEARCH
  • 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 7435895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:09:06+00:00 2026-05-29T10:09:06+00:00

I have a variable on my page called, $recipe[‘ingredients’]; inside the var you have

  • 0

I have a variable on my page called, $recipe['ingredients'];

inside the var you have as follows,

100ml milk, 350ml double cream, 150ml water

and so on. Now I’m trying to split it up so it looks as follows

<ul>
    <li>100ml milk</li>
    <li>350ml double cream</li>
    <li>150ml water</li>
</ul>

So far I have the following code,

$ingredientsParts = explode(',', $row_rs_recipes['ingredients']);
$ingredients = array($ingredientsParts);
while (! $ingredients) { 
   echo" <li>$ingredients</li>";
}

But for some reason it doesn’t work and I do not have the experience with explode to fix it.

  • 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-05-29T10:09:07+00:00Added an answer on May 29, 2026 at 10:09 am
    1. When you explode() a string it is automatically converted into an array. You do not need to convert it to an array type as you did on the second line.
    2. You want to use a foreach() loop to iterate through an array, not a while loop.

         $ingredientsAry = explode(',', $row_rs_recipes['ingredients']);
         foreach($ingredientsAry as $ingredient){
             echo "<li>$ingredient</li>";
         }
      

    In fact you can just do a foreach() loop on the explode() value

    foreach(explode(',', $row_rs_recipes['ingredients']) as $ingredient){
        echo "<li>$ingredient</li>";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have session variable called page views. When my page is loaded I have
I have a class level price variable decalred inside a page, like this: public
I have a page (view) called test. It has 3 links with a variable?vars='some_number'
I have a javascript file called pendingAjaxCallsCounter.js with a variable var pendingAjaxCalls which is
I have a page called index.html which takes in a few variable from the
I have a List variable called services in my JSP page. I need to
I have a page called Error.php. Variables are usually passed to it using the
i have a variable $cartTotal in cart.php page i want to use that same
I have a variable that contains the entire html for a page as a
I have some variable where everytime the form is submiited or page is refreshed,

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.