I have input like this:
$recipe['ingredients'] = '100ml milk, 350ml double cream, 150ml water';
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 nothing gets printed.
explode()returns an array: php.net/manual/en/function.explode.php$ingredients = array($ingredientsParts);You don't need this.ingredientsPartsis already an array after explosion. I would, personally, usefororforeachloop to traverse whole array but that's up to you. I'm not sure if it could be done by thiswhilecondition. Are you trying to reference to array internal pointer by!$ingredients?