Jump to content

[SOLVED] Ordered list within an array


ironman32

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.