PHP: loop trought array and create li list with array elements - array in array -
i have an array objects:
array ( [0] => 479,1,sometext [1] => 474,2,again text [2] => 472,3,and text )
the objects in array can unlimited, each object consists of 3 parts delimited comma .
the result should (in example)- corrected secondly
<li> <span class="somecrap">array[0][0]</span> <input type="text" class="secondcrap" value="array[0][1]"/> <textarea class="3crap">array[0][2]</textarea> </li> <li> <span class="somecrap">array[1][0]</span> <input type="text" class="secondcrap" value="array[1][1]"/> <textarea class="3crap">array[1][2]</textarea> </li> <li> <span class="somecrap">array[2][0]</span> <input type="text" class="secondcrap" value="array[2][1]"/> <textarea class="3crap">array[2][2]</textarea> </li>
etc.... depending of count of array objects
how accomplish this?
try this:
foreach($array $entry) { echo "<li>\n"; $elements = explode(',', $entry, 3); echo "<span class='somecrap'>{$elements[0]}</span>\n"; echo "<input type='text' class='secondcrap' value='{$elements[1]}'/>\n"; echo "<textarea class='3crap'>{$elements[2]}</textarea>\n"; echo "</li>\n"; }
updated reflect edited requirements. untested.
Comments
Post a Comment