admin管理员组

文章数量:1430077

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?

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?

Share Improve this question edited Apr 26, 2019 at 4:41 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Apr 25, 2019 at 20:11 BrentBrent 8032 gold badges8 silver badges17 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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?

本文标签: databaseI Want a More Concice Form of Data than an Array