How to create a nested array from current array in PHP?

186
January 01, 2021, at 11:00 AM

I am trying to read the categories in an XML file from my API provider. The only problem is that they nested the subcategories in a string:

[
{category: "root|sub|another_sub"},
{category: "root|sub2},
{category: "sibling|sub|foo"),
{category: "root|sub|foo")
]

I need to display the above data in a nested html list like:

<li>
  root
  <ul>
    <li>sub 
      <ul>
        <li>another_sub</li>
      </ul> 
      <ul>
        <li>foo</li>
      </ul>
    </li>
    <li>sub 2</li>
  </ul>
  <li>sibling
    <ul>
      <li>sub
        <ul>
          <li>foo</li>
        </ul>
      </li>
    </ul>
</li>

I literally can't think of a solution to do this dynamically.. I tried using multiple loops and array_reduce but no success. Can someone explain how this works?

Rent Charter Buses Company
READ ALSO
Configuring sqlalchemy engine with user containing &ldquo;:&rdquo;

Configuring sqlalchemy engine with user containing “:”

I am trying to configure an engine in sqlalchemy to connect with temporary credentials from an AWS IAM role using get_cluster_credentials apiWhen I do so this is the user I get 'IAM:user_rw'

214
Transform is not applied on Embedded SVGs Chrome

Transform is not applied on Embedded SVGs Chrome

I am new to using SVGs, but everything was fine until I tried my code on chrome and found that it doesn't work properly, all transform attributes are neglectedFirefox gets it done as expected

40
JavaScript Memory Model with Process Memory model

JavaScript Memory Model with Process Memory model

I'm studying Process Memory model and got curious with JavaScript's memory model

162
mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python &#39;list&#39; cannot be converted to a MySQL type

mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python 'list' cannot be converted to a MySQL type

I am attempting to insert a value into my table where it selects an ID by matching it with its name and inserting it into a second tableHowever when I print out the selected value it prints [(1,)] which is classed as a list

377