...

View Full Version : Custom Array Function



DJCMBear
04-06-2010, 11:31 PM
I thought I would post this function I created for others to use.



<?php
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
}
}
}
return $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])



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum