<?php
function dict_check($d, $s) { //function declaration taking 2 params d and s (descriptive vars make code easier to read!!)
if ($d["type"] != "dictionary") // if the value of the array $d with the key type does not equal the string dictionary
bark("not a dictionary"); //call user defined function bark() and pass the string to it "not a dictionary"
$a = explode(":", $s); //break apart the variable $s into an array by using the : character and save it to $a;
$dd = $d["value"]; //the var $dd equals the value of the array $d with the key "value"
$ret = array(); // the var $ret is declared an array
foreach ($a as $k) { //loop through the array $a replacing its value w/ $k
unset($t); // make the var $t empty or null
if (preg_match('/^(.*)\((.*)\)$/', $k, $m)) { // if $k matches $m via a perl compatible regular expression
$k = $m[1]; // then the var $k equals the second value of the array $m
$t = $m[2];//and the var $t equals the third value of the array $m
} // end if
if (!isset($dd[$k])) //if the value of the array $dd w/ the associative index of $k is not set
bark("dictionary is missing key(s)"); //call the function bark w/ the param 'dictionary is missing key..'
if (isset($t)) { // if the value of $t is set
if ($dd[$k]["type"] != $t) // if the value of the array $dd with the associative key of the array $k with the associative key of 'type'
bark("invalid entry in dictionary"); //call bark with string params
$ret[] = $dd[$k]["value"]; //the array $ret equals the array $dd with the associative key of $k and the associative key of 'value'
}// end if
?>
Whew I did my best to translate that into english for fun practice 🙂
I might have messed up badly I think my parsers off kilter...
Anyways that code makes little sense because the vars are named as letters which have no meaning. As w/ anything in programming descriptive and verbose names help you know what each line is talking about by giving you hints at the var name level .
Good Luck
MiramarDesign
http://miramardesign.com
I code therefore I am.