• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Array Question


I'm trying to create an add-on that uses multi-selection check boxes (such as admin.php?options/edit-option/spamDefaultOptions).

I've managed to get the output I want by simply editing the sub-array names to be what I want and then using the following in my template;

AddOn_Template said:
<xen:if is="{xen:checked $xenOptions.Option ID.Array Sub-Option}">Content</xen:if>
However, I don't really understand what the values in array mean.

admin.php?options/edit-option/spamDefaultOptions said:
I have figured out that a:5 is because you have 5 array sub-options and the numbers in quotes (1 or 0) appear to dictate whether the check box should be checked (1) or unchecked (0) by default. It is the rest of the letters/numbers I don't understand, s:1, s:9, etc.

What does these values mean? Any help greatly appreciated.
Sorry, I don't understand what you mean as my knowledge of PHP is non existant.

s denotes "serialised" and the number the order in the series which the sub-option appears/is executed? If it's possible to un-serialise an array, then what befits does serialising have to begin with?

Could the above example be simplified to something like;

AddOnOption said:

I'm able to get working multiple check boxes to work without creating any php files (such as listener.php, addon.php etc., which I can't fully get my head round) by doing the following options;

admin.php?options/edit-option/AddOn said:
Edit Format said:
Check Boxes
Format Parameters said:
value_1 = Value 1
value_2 = Value 2
value_3 = Value 3
Data Type said:
Array Sub-Options said:
The issue arises as I'd like to be able to specify which of the check boxes are pre-checked and which aren't. Is this possible without going through the process of listener and other php files?


Well-known member
Well, if you execute this code
$a = unserialize('a:5:{s:8:"ban_user";s:1:"1";s:15:"delete_messages";s:1:"1";s:14:"action_threads";s:1:"1";s:9:"check_ips";s:1:"1";s:10:"email_user";s:1:"0";}');
You will get this:
     [ban_user] => 1
     [delete_messages] => 1
     [action_threads] => 1
     [check_ips] => 1
     [email_user] => 0
Serialization is a way to put a variable (array in this case) to string.
If you wish to know what the "s" means, it represents string type, and the number after it represents string length, but you shouldn't really care about it, you need only to use serialize() and unserialize() functions and manipulate with arrays as usual.
Ah, I get it now.

The reason I couldn't get it to work for my add on was that I had the wrong string length for my array sub options.

I changed;

Default Value said:

Default Value said:
and then it worked as expected.

Thanks to both of you for your help :).