Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

How to create an array/object from an ordered list?

How can I create an array from an ordered list, with the number as the index/key and the list item as the array value?

Example list:

<ol>
  <li>First list item</li>
  <li>Second list item</li>
  <li>Third list item</li>
</ol>

Should result in:

{"1" => "First list item", "2" => "Second list item", "3" => "Third list item"}

I tried using Array.from() with a few variations but that didn't work

0 likes
2 replies
jlrdw's avatar

Do this separate like in controller.

1 like
Ligonsker's avatar

@jlrdw Thanks, I ended up doing so in JavaScript and sending the array with AJAX

Please or to participate in this conversation.