0

This is pretty abstract and isn't truly WordPress related, except that I'm storing this data in a WordPress installation, so I am limited to PHP/MySQL-esque parameters.

Here's what I want to do. I've got a list of Post ID's that I need to store in specific arrangements, different from their nested order as presented by WordPress. For example:

  • ID 101
    • ID 106
      • ID 115
      • ID 116
    • ID 107
      • ID 117
    • ID 108
      • ID 118
      • ID 119
      • ID 120
    • ID 109
  • ID 102
    • ID 110
      • ID 121
      • ID 122
    • ID 111
      • ID 123
    • ID 112
  • ID 103
    • ID 113
    • ID 114
  • ID 104
  • ID 105

The idea here is that this is a deep and complex list that could go on recursively forever if needed.

Now I could create a set of nested arrays to house this structure in PHP, but that feels a little sloppy on my end. My question is this: Is there a simpler/cleaner way to store this complex list of nested ID's -- A JSON list, XML list or some other form of data that could be programmatically manipulated as needed?

0

Instead of going for a complex nested array, I decided that it might be best to keep it to simple two level set of arrays.

    $x = array(
            101 => [ (int $parent_id), (bool $completed)  ], 
            102 => [ (int $parent_id), (bool $completed)  ], 
            103 => [ (int $parent_id), (bool $completed)  ], 
            104 => [ (int $parent_id), (bool $completed)  ], 
            ...
        );

I realized that I was looking for something simpler like what python offers with its "list" data type. I feel like this is about as simple as I could get with storing an unorder list in PHP/MySQL. Anyone got anything better?

  • the $completed variable was another reason to go with this design choice, which I didn't mention in the original question. – Brent Apr 25 '19 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.