public function GetParks($request) { $sql = "select * \n\t\t\t\t\tfrom " . DB_PREFIX . "park p\n\t\t\t\t\t\tleft join " . DB_PREFIX . "parktitle pt on pt.parktitle_id = p.parktitle_id\n\t\t\t\t\twhere p.park_id = '" . mysql_real_escape_string($request['ParkId']) . "' and p.parent_park_id > 0\n\t\t\t\t\torder by pt.class desc, p.name asc"; $r = $this->db->query($sql); if ($r !== false && $r->size() > 0) { $response = array('Status' => Success(), 'Parks' => array()); do { $response['Parks'][] = array('ParkId' => $r->park_id, 'KingdomId' => $r->kingdom_id, 'ParentParkId' => $r->parent_park_id, 'Name' => $r->name, 'Abbreviation' => $r->abbreviation, 'Url' => $r->url, 'Directions' => stripslashes(nl2br($r->directions)), 'Location' => $r->location, 'ParkTitleId' => $r->parktitle_id, 'Active' => $r->active, 'Title' => $r->title, 'Class' => $r->class, 'ParentOf' => $r->is_principality == 1 && !array_search($r->park_id, $request['Stack']) ? $this->GetParks(array('ParkId' => $r->park_id, 'Stack' => push_stack($request['Stack'], $r->park_id))) : null); } while ($r->next()); } else { $response['Status'] = InvalidParameter(); } return $response; }
/** * function push_on_front_convoArr() * A function to push items on the front of a subarray in convoArr * @param array $arrayIndex - the subarray index to push to * @param array $value - the value to push on teh subarray * @param array $convoArr - the current state of the conversation array * @return $convoArr (updated) * TODO BETTER COMMENTING **/ function push_on_front_convoArr($arrayIndex, $value, $convoArr) { global $offset, $rememLimit; runDebug(__FILE__, __FUNCTION__, __LINE__, "Pushing {$value} to front of {$arrayIndex} array", 4); $remember_up_to = $convoArr['conversation']['remember_up_to']; //these subarray indexes are 2d $two_d_arrays = array("that", "that_raw"); $arrayIndex = trim($arrayIndex); //mini clean $value = trim($value); $value = preg_replace('/\\s\\s+/', ' ', $value); $value = preg_replace('/\\s\\./', '.', $value); //there is a chance the subarray has not been set yet so check and if not set here if (!isset($convoArr[$arrayIndex][$offset])) { $convoArr[$arrayIndex] = array(); $convoArr = load_blank_convoArray($arrayIndex, "", $convoArr); } //if the subarray is itself an array check it here if (in_array($arrayIndex, $two_d_arrays)) { $matches = preg_match_all("# ?(([^\\.\\?!]*)+(?:[\\.\\?!]|(?:<br ?/?>))*)#ui", $value, $sentances); $cmatch = 0; //do another check to make sure the array is not just full of blanks foreach ($sentances as $temp) { foreach ($temp as $chk) { if (trim($chk) != "") { $cmatch++; } } } runDebug(__FILE__, __FUNCTION__, __LINE__, print_r($convoArr[$arrayIndex], true), 4); //if there definately is something in the sentance array build the temp sentance array if ($cmatch > 0 && $matches !== FALSE) { foreach ($sentances[1] as $index => $value) { if ($arrayIndex == "that") { $t = clean_that($value); if ($t != "") { $tmp_sentance[] = $t; } } else { $tmp_sentance[] = $value; } } //reverse the array and store $sentances = array(); $sentances = array_reverse($tmp_sentance); } else { $sentances = array(); if ($arrayIndex == "that") { $sentances[0] = clean_that($value); } else { $sentances[0] = $value; } } //make a space so that [0] is null (in accordance with the AIML array offset) array_unshift($sentances, NULL); unset($sentances[0]); //push this onto the subarray and then clear [0] element (in accordance with the AIML array offset) array_unshift($convoArr[$arrayIndex], $sentances); array_unshift($convoArr[$arrayIndex], null); unset($convoArr[$arrayIndex][0]); } else { array_unshift($convoArr[$arrayIndex], $value); array_unshift($convoArr[$arrayIndex], NULL); } if (trim($arrayIndex) == 'star' || trim($arrayIndex) == 'topic') { //keep 5 times as many topics and stars as lines of conversation $rememLimit_tmp = $rememLimit; } else { $rememLimit_tmp = $remember_up_to; } for ($i = $rememLimit_tmp + 1; $i <= count($convoArr[$arrayIndex]); $i++) { if (isset($convoArr[$arrayIndex][$i])) { unset($convoArr[$arrayIndex][$i]); } } unset($convoArr[$arrayIndex][0]); if ($arrayIndex == "topic") { push_stack($convoArr, $value); } return $convoArr; }
<?php $stack = array(); function push_stack() { global $stack; static $index = 0; $val = $index++; array_push($stack, $val); } function pop_stack() { global $stack; if ($stack) { array_pop($stack); } } push_stack(); pop_stack(); pop_stack(); pop_stack(); push_stack(); pop_stack(); push_stack(); $info = array(count($stack), $stack[count($stack) - 1], $stack); var_dump($info);