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

Array Question

Discussion in 'XenForo Development Discussions' started by Gaming Perfection, Oct 24, 2010.

  1. Hi,

    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;

    However, I don't really understand what the values in array mean.

    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.
     
  2. Boothby

    Boothby Active Member

    Unserialize the array.
    Code:
    Array
    (
         [ban_user] => 1
         [delete_messages] => 1
         [action_threads] => 1
         [check_ips] => 1
         [email_user] => 0
    )
     
    Gaming Perfection likes this.
  3. 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;

    ?

    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;

    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?
     
  4. g0rn

    g0rn Well-Known Member

    Well, if you execute this code
    PHP:
    $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";}');
    print_r($a);
    print(
    serialize($a));
    You will get this:
    Code:
    Array
    (
         [ban_user] => 1
         [delete_messages] => 1
         [action_threads] => 1
         [check_ips] => 1
         [email_user] => 0
    )
    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";}
    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.
     
    Gaming Perfection likes this.
  5. 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;



    to;



    and then it worked as expected.

    Thanks to both of you for your help :).
     

Share This Page