OK, this may sound like an odd question so first let me lay out the basic situation:
At our company we're using a ticketsystem. This system has a FAQ dbase. I can't change the structure of the database in any way because we would have to change the ticketsystem to cope with that change and that is not an option.
So with that out of the way...
Because there is no seperate field available we add a chapter number to the title of every item to have a sort of index.
So you'd get something like this:
1 start
1.1 some subchapter
2 new chapter
3 another chapter
3.1 sub of chapter
3.1.1 sub sub chapter
etc..
Offcourse with a nifty regex it's easy to extra the chapter part from the string. But the next step would be to make it easy to find the corresponding subchapters based on the parent chapter. Easiest way to make this searchable without a database would be a multidimensional array, right?
So you would get this:
array( 3 => array(
'item' => 'data', 1 => array('item', 2 = array() ) ) ) etc...
What I've done now is to create an array of chapter indexes ( [3,1,1] in the case of 3.1.1 ) and because I know the there are always between 1 and 3 items in this array I made a switch based on the array length and then did this:
$array[$index[0]][$index[1]]['item'] = $content;
But I feel this is a very dirty and unlfexible way of doing this. Normally I'd vote for changing the database structure no matter what, but without that option I'm unsure what the best method would be.
Any help would be great!
EDIT: Added my comment below for better readability
Titles are one line indeed, but that part I have working with a regex to extract the chapter part. So that's working.
What I basicly build is a form that uses the array of indexes to build a list of checkboxes for each chapter or chapterpart. But I don't want to search through the array and compare keys to find subchapters. So if I'd choose 3.1 I'd check 3.1.1, 3.1.2 and because the key starts with 3.1 I'd know to print it.
Faster would be to be able to do this:
Choose 3.1.1 => return $chapters[3][1][1]['item']
But that's only possible when I can build the initial array in that form.