ironman32 Posted March 31, 2009 Share Posted March 31, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/151976-solved-ordered-list-within-an-array/ Share on other sites More sharing options...
Cosizzle Posted March 31, 2009 Share Posted March 31, 2009 outside the array... <ul> array <li></li> <ul> Quote Link to comment https://forums.phpfreaks.com/topic/151976-solved-ordered-list-within-an-array/#findComment-798104 Share on other sites More sharing options...
kenrbnsn Posted March 31, 2009 Share Posted March 31, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/151976-solved-ordered-list-within-an-array/#findComment-798115 Share on other sites More sharing options...
ironman32 Posted March 31, 2009 Author Share Posted March 31, 2009 My main aim is to have an array with ordered lists as the elements. These will then be called at random. So first I need to find a way of having ordered lists as elements. Quote Link to comment https://forums.phpfreaks.com/topic/151976-solved-ordered-list-within-an-array/#findComment-798124 Share on other sites More sharing options...
kenrbnsn Posted March 31, 2009 Share Posted March 31, 2009 Please explain better. Perhaps an example would help. Ken Quote Link to comment https://forums.phpfreaks.com/topic/151976-solved-ordered-list-within-an-array/#findComment-798129 Share on other sites More sharing options...
ironman32 Posted March 31, 2009 Author Share Posted March 31, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/151976-solved-ordered-list-within-an-array/#findComment-798146 Share on other sites More sharing options...
premiso Posted March 31, 2009 Share Posted March 31, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/151976-solved-ordered-list-within-an-array/#findComment-798147 Share on other sites More sharing options...
ironman32 Posted March 31, 2009 Author Share Posted March 31, 2009 I've tried it out and you're right it does exactly what I needed. Thanks everyone for all the help Quote Link to comment https://forums.phpfreaks.com/topic/151976-solved-ordered-list-within-an-array/#findComment-798150 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.