Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    United Kindom
    Thanked 136 Times in 136 Posts

    Thumbs up Custom Array Function

    I thought I would post this function I created for others to use.

    PHP Code:
    function custom_array($str){
    /* Config Options */
    $array_prefix  "[:]"// Custom array start:finish ':' split them up
    $array_split   ":"// Array split (i:0;) ':' splits the key and var
    $var_end       ";"// Var end (i:0;) ';' ends the current var
      /* Config Options */
    list($as,$af)  = split(':',$array_prefix); // Splitting up the array prefix's
    if(substr($str,0,1) == $as && substr($str,-1) == $af){ // Checks custom array start/finish
    $array = array(); // Starts the array
    foreach(split($var_end,substr($str,1,-1)) As $create){ // Extracting each array query
    if($create != ""){ // Checks if array vars contain something
    list($key,$value) = split($array_split,$create); // Splits custom array vars
    if($value != ""){ // Checks if array value contain something
    $array[$key] = $value// Sets array key / value
    $array// Returns the final array
    $entry "[i:0;j:23;ii:1;]"// My custom array string
    $entry custom_array($entry); // array([i] => 0 [j] => 23 [ii] => 1);
    print $entry[j]; // returns '23'
    Hope people like my function which you can mod to how you want your custom array to look
    e.g. ([i::0],[j::23],[ii::1])
    Last edited by DJCMBear; 04-08-2010 at 12:59 AM.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts