- This topic has 7 replies, 2 voices, and was last updated 7 years, 7 months ago by
egnsh98.
-
AuthorPosts
-
-
June 27, 2014 at 10:59 am #1905
egnsh98MemberHello,
I know this is more of a general PHP question than it is Piklist, but I figured I would post it here anyways.
The Setup

What I am trying to do
On each iteration, grab the value of each field for that particular group. For example the first group box:
- Category => Anime
- Time => 01:00
- Format => woot
and so on…
Actual Behaviour
On each iteration, the same fields in the different group boxes are being stored together, rather than apart. I’m posting the formatted output so you can see what I mean:
a:8:{ s:11:"group"; a:3:{ s:9:"cat"; a:2:{ i:0; s:4:"3722"; i:1; s:2:"20"; } s:10:"time"; a:2:{ i:0; s:1:"1"; i:1; s:1:"2"; } s:12:"output"; a:2:{ i:0; s:4:"woot"; i:1; s:5:"hello"; } } }And this is how I am trying to retrieve them…
// Loop through options foreach ( $options as $field_group ) { // Check type if ( is_array( $field_group ) ) { // Loop through field groups foreach ( $field_group as $field_arr ) { // Check type if ( is_array( $field_arr ) ) { // Loop through fields foreach ( $field_arr as $field ) { // Print results echo $field; } } } } }The output from my above loops looks like this:
37222012woothelloI need to access and store each field from the first group before moving onto the second group.
Would anyone be able to give me some advice on how to go about this?
Thanks
-
June 27, 2014 at 11:25 am #1906
SteveKeymasterDue to the nature of the Add-mores and how powerful they are, we had to use an unconventional array structure. But don’t worry, Piklist helps you get the data out.
Check out the docs on Add-More’s. It’s explained in detail.
Let us know if you still need help.
-
June 27, 2014 at 11:29 am #1907
egnsh98MemberShould have checked that out first. Thanks a lot for the reference, I’ll have a look over it now 🙂
-
June 27, 2014 at 1:53 pm #1908
egnsh98MemberSteve,
I’ve managed to get the values outputting on the screen for test purposes as I had wanted. Only issue is the values are being output in the add_more template file, not in the main class file that I am working with. How should I access those variables, will I need to create getters and setters to move that data between files or is there a better way?
The structure for this data in my main class file looks something like this:
// Get the schedule group information $schedule_group = $options['sched_group']; // 1. Display the data using the file schedule_template.php. // 2. Assign your $sched_cat parameter (from above) to 'data'. // 3. Loop through 'data'. piklist('schedule_template', array('data' => $schedule_group, 'loop' => 'data')); $sched_category_id = $data['sched_cat']; $sched_timestamp = $data['sched_time']; $sched_format = $data['sched_format']; var_dump ( $sched_category_id . $sched_timestamp . $sched_format );Regards.
-
June 27, 2014 at 2:12 pm #1909
SteveKeymasterWorking with multi-dimensional arrays is never fun, that’s why we made it easy to output data. However, if you want to access the variables and work with them you are going to have to create your own methods.
The array is structure so all the data is in order. All key [1] is related to the same add-more for example.
-
June 27, 2014 at 2:36 pm #1910
egnsh98MemberOkay thanks. Would I be better off going my initial route when I first opened this topic, or can I still use the piklist functions to help breakdown the array? I have trouble wrapping my head around some of this stuff.
-
June 27, 2014 at 4:56 pm #1911
SteveKeymasterSince it’s only a single level add-more it might be easier to just loop through it the way you originally suggested.
-
July 4, 2014 at 1:53 pm #1951
egnsh98MemberYou are right, it was much easier. This is resolved now.
-
-
AuthorPosts
- The topic ‘Settings Array’ is closed to new replies.