Ways of dealing with nested arrays within option

This is a typical situation for using a class to manage a data structure. You got a complex data structure and you need some functions to retrieve and modify the data structure. This is easy made with a class.

The class get the data structure from the database and have some methods to get parts of the data structure or modify them.

I wrote a sample class, you can extend or modify it with your own methods. Using the class is very simple:

  <?php
  // creating an instance of the class and retrieve the data from db
  $collections = new CollectionsManager();

  // get a collection by it's id
  $sample_collection = $collection->get_collection_by_id( 'sample_collection' );

  // get the elements of the sample collection
  $sample_elements = $collection->get_elements_by_id( 'sample_collection' );

  // insert an alement
  $new_element = array( 'id' => 5, 'name' => 'new_element', 'url' => 'http://wordpress.stackexchange.com' );
  $new_element_id = $collection->insert_element_by_id( 'sample_collection', $new_element );

I wrote this class from scratch and it is not been tested yet. Maybe it’s buggy in some parts. I give no warranty for bugless functionality!