Jump to content

Recommended Posts

Does anyone know how to put an ordered list inside an array. i've already attempted it but was not successful

 

$input2 = array(("<ol><li><a href =\"http://www.muscleandstrength.com/exercises/barbell-bench-press.html\">Bench press</a></li>"
"<li><a href =\"http://www.muscleandstrength.com/exercises/military-press-behind-neck.html\">Military Press behind the neck</a>"</li></ol>",
);

 

Does anyone know how to do this or if this is possible?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/151976-solved-ordered-list-within-an-array/
Share on other sites

What do you want to do with this?

 

If you want to create an ordered list from the elements of the array, you can do something like this:

<?php
$ol = array('<a href ="http://www.muscleandstrength.com/exercises/barbell-bench-press.html">Bench press</a>',
      '<a href ="http://www.muscleandstrength.com/exercises/military-press-behind-neck.html">Military Press behind the neck</a>');
echo '<ol><li>' . implode("</li>\n<li>",$ol) . "</li></ol>\n";
?>

 

Ken

What I am aiming to do is to have a full list within an array e.g.

$input1 = array(<ol><li><a href =\"http://www.muscleandstrength.com/exercises/barbell-bench-press.html\">Bench press</a></li>
<li><a href =\"http://www.muscleandstrength.com/exercises/military-press-behind-neck.html\">Military Press behind the neck</a></li>
<li><a href=\"http://www.liverpoolfc.tv\">A</a>","<a href =\"http://www.muscleandstrength.com/exercises/military-press-behind-neck.html\">C</a>"</li>
<li>"<a href =\"http://www.muscleandstrength.com/exercises/military-press-behind-neck.html\">B</a></li></ol>")

 

So it can produce an output like this

 

1.Bench press

2.Military press behind the neck

3.C

4.B

 

Is that more understandable?

If you want to create an ordered list from the elements of the array, you can do something like this:

<?php
$ol = array('<a href ="http://www.muscleandstrength.com/exercises/barbell-bench-press.html">Bench press</a>',
      '<a href ="http://www.muscleandstrength.com/exercises/military-press-behind-neck.html">Military Press behind the neck</a>');
echo '<ol><li>' . implode("</li>\n<li>",$ol) . "</li></ol>\n";
?>

 

Did you not try this out? It does exactly what you are asking. Except, instead of it being kept in an array as that form, it converts it at runtime so the data stays in it's raw form and is not manipulated till it needs to be displayed.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.