Beispiel #1
0
function normalize_result($res)
{
    $ret = $res->return;
    $obj_vars = get_object_vars($ret);
    if (count($obj_vars) > 0) {
        return make_array(reset($obj_vars));
    } else {
        return array();
    }
}
Beispiel #2
0
function insertion_sort()
{
    $list = make_array(10000);
    for ($i = 1; $i < count($list); $i++) {
        $val = $list[$i];
        $index = $i - 1;
        while ($index >= 0 && $val < $list[$index]) {
            $temp = $list[$index];
            $list[$index] = $val;
            $list[$index + 1] = $temp;
            $index--;
        }
    }
    return $list;
}
Beispiel #3
0
 /**
  *
  * @param unknown_type $fields
  * @param unknown_type $table
  * @param unknown_type $wheres
  * @param str $is_calck_count =true для подсчёта количества SQL_CALC_FOUND_ROWS (см $this->is_use_SQL_CALC_FOUND_ROWS). Можно задать свой SQL-запрос для подсчёта кол-ва
  * @param unknown_type $limit
  * @param unknown_type $order
  * @param unknown_type $group
  */
 protected function init_from_db_($fields = '*', $table, $wheres = array(), $is_calck_count = false, $limit = '', $order = '', $group = '')
 {
     if ($this->fields != null) {
         $fields = $this->fields;
     }
     $this->res = array();
     $this->res_first = array();
     $this->enable = FALSE;
     $this->count = 0;
     $wheres = make_array($wheres);
     $where = c_db::make_where($wheres);
     $limit = c_db::make_limit($limit);
     $order = c_db::make_order($order);
     $group = c_db::make_group($group);
     $add = '';
     if ($is_calck_count === true && ($this->is_use_SQL_CALC_FOUND_ROWS || !empty($group))) {
         //если группируем, то лучше считать по SQL_CALC_FOUND_ROWS, т.к. иначе
         // 1) в случае подсчёта count без группировки результат будет неверным
         // 2) с группировкой - агрегатная функция count(*) будет считать количество внутри группы и нам придётся считать кол-во рядов вручную, что не быстрее
         $add = "SQL_CALC_FOUND_ROWS";
     }
     $sql = "SELECT  {$add}\n            {$fields}\n          FROM {$table}\n          {$where}\n          {$group}\n          {$order}\n          {$limit}";
     if ($this->is_debug) {
         echo '<BR>Class: <B>' . get_class($this) . '</B><BR>';
     }
     $this->res = $this->db->get_array($sql, array());
     if (!empty($this->res)) {
         $this->res_first = $this->res[0];
         $this->enable = true;
         if ($is_calck_count !== false) {
             $c = array();
             if ($is_calck_count === true) {
                 if ($this->is_use_SQL_CALC_FOUND_ROWS || !empty($group)) {
                     $sql = 'SELECT FOUND_ROWS() as count';
                 } else {
                     $sql = "SELECT count(*) as count\n                  FROM {$table}\n                  {$where}";
                 }
             } else {
                 $sql = $is_calck_count;
             }
             $c = $this->db->get_array_first_record($sql);
             $this->count = $c['count'];
         }
     }
     return $this->res;
 }
Beispiel #4
0
     } else {
         $array_tmp = make_array($result, 'id_product_attribute');
         $array_0 = array_intersect($array_0, $array_tmp);
         if (count($array_0) == 0) {
             break;
         }
     }
 }
 //	Get the intersection for all the parameters
 $result_1 = DB::getInstance()->ExecuteS('SELECT combination.id_product_attribute FROM ' . _DB_PREFIX_ . 'product_attribute_combination AS combination LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute AS ' . ' attribute ON combination.id_product_attribute = attribute.id_product_attribute WHERE combination.id_attribute = ' . $attribute_id . ' AND attribute.id_product = ' . $request_product . ' AND ' . 'attribute.aimd_value = 1');
 $array_1 = make_array($result_1, 'id_product_attribute');
 $result_2 = DB::getInstance()->ExecuteS('SELECT combination.id_product_attribute FROM ' . _DB_PREFIX_ . 'product_attribute_combination AS combination LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute AS ' . 'attribute ON combination.id_product_attribute = attribute.id_product_attribute WHERE combination.id_attribute = ' . (int) $request_attr_2 . ' AND attribute.aimd_value = 1');
 $array_2 = make_array($result_2, 'id_product_attribute');
 if ($request_attr_3 != '-1' && $request_attr_3 != '') {
     $result_3 = DB::getInstance()->ExecuteS('SELECT combination.id_product_attribute FROM ' . _DB_PREFIX_ . 'product_attribute_combination AS combination LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute ' . 'AS attribute ON combination.id_product_attribute = attribute.id_product_attribute WHERE combination.id_attribute = ' . (int) $request_attr_3 . ' AND attribute.aimd_value = 1');
     $array_3 = make_array($result_3, 'id_product_attribute');
 }
 //	Get the intersection ...
 $result = array();
 if (count($array_0)) {
     if (isset($array_3)) {
         $result = array_intersect($array_0, $array_1, $array_2, $array_3);
     } else {
         $result = array_intersect($array_0, $array_1, $array_2);
     }
 }
 //	If combination not found, we create it
 if (empty($result)) {
     //	Default reference and image
     $reference = '';
     $image = -1;
Beispiel #5
0
 function get_params_POST($param_names = array(), $default = '', $is_number = false, $min = '', $max = '')
 {
     $res = array();
     $param_names = make_array($param_names);
     foreach ($param_names as $param_name) {
         $res[$param_name] = $this->get_param_POST($param_name, $default, $is_number, $min, $max);
     }
     return $res;
 }
Beispiel #6
0
function display_deliveries($binding)
{
    $deliveries = get_all_deliveries($binding);
    if ($deliveries) {
        echo "<deliveries count=\"" . count($deliveries) . "\">\n";
        foreach ($deliveries as $delivery) {
            echo "<delivery id=\"" . $delivery->id . "\" start=\"" . $delivery->start . "\" messageId=\"" . $delivery->messageId . "\" status=\"" . $delivery->status . "\">\n";
            if (isset($delivery->recipients)) {
                $recipients = make_array($delivery->recipients);
                echo "<recipients count=\"" . count($recipients) . "\">\n";
                foreach ($recipients as $recipient) {
                    echo "<recipient type=\"" . $recipient->type . "\" id=\"" . $recipient->id . "\"/>\n";
                }
                echo "</recipients>\n";
            }
            echo "</delivery>\n";
        }
        echo "</deliveries>\n";
    }
}
Beispiel #7
0
function get_next_token(&$pos)
{
    global $last_type, $last_text;
    global $whitespace, $wordchar, $punct;
    global $input, $input_length;
    if (!$whitespace) {
        $whitespace = make_array("\n\r\t ");
    }
    if (!$wordchar) {
        $wordchar = make_array('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$');
    }
    if (!$punct) {
        $punct = explode(' ', '+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! !! , : ? ^ ^= |=');
    }
    $n_newlines = 0;
    do {
        if ($pos >= $input_length) {
            return array('', TK_EOF);
        }
        $c = $input[$pos];
        $pos += 1;
        if ($c == "\n") {
            nl($n_newlines == 0);
            $n_newlines += 1;
        }
    } while (in_array($c, $whitespace));
    if (in_array($c, $wordchar)) {
        if ($pos < $input_length) {
            while (in_array($input[$pos], $wordchar)) {
                $c .= $input[$pos];
                $pos += 1;
                if ($pos == $input_length) {
                    break;
                }
            }
        }
        // small and surprisingly unugly hack for 1E-10 representation
        if ($pos != $input_length and preg_match('/^\\d+[Ee]$/', $c) and $input[$pos] == '-') {
            $pos += 1;
            list($next_word, $next_type) = get_next_token($pos);
            $c .= '-' . $next_word;
            return array($c, TK_WORD);
        }
        if ($c == 'in') {
            // hack for 'in' operator
            return array($c, TK_OPERATOR);
        }
        return array($c, TK_WORD);
    }
    if ($c == '(' || $c == '[') {
        return array($c, TK_START_EXPR);
    }
    if ($c == ')' || $c == ']') {
        return array($c, TK_END_EXPR);
    }
    if ($c == '{') {
        return array($c, TK_START_BLOCK);
    }
    if ($c == '}') {
        return array($c, TK_END_BLOCK);
    }
    if ($c == ';') {
        return array($c, TK_END_COMMAND);
    }
    if ($c == '/') {
        // peek for comment /* ... */
        if ($input[$pos] == '*') {
            $comment = '';
            $pos += 1;
            if ($pos < $input_length) {
                while (!($input[$pos] == '*' && isset($input[$pos + 1]) && $input[$pos + 1] == '/') && $pos < $input_length) {
                    $comment .= $input[$pos];
                    $pos += 1;
                    if ($pos >= $input_length) {
                        break;
                    }
                }
            }
            $pos += 2;
            return array("/*{$comment}*/", TK_BLOCK_COMMENT);
        }
        // peek for comment // ...
        if ($input[$pos] == '/') {
            $comment = $c;
            while ($input[$pos] != "\r" && $input[$pos] != "\n") {
                $comment .= $input[$pos];
                $pos += 1;
                if ($pos >= $input_length) {
                    break;
                }
            }
            $pos += 1;
            return array($comment, TK_COMMENT);
        }
    }
    if ($c == "'" || $c == '"' || $c == '/' && ($last_type == TK_WORD and $last_text == 'return' or $last_type == TK_START_EXPR || $last_type == TK_END_BLOCK || $last_type == TK_OPERATOR || $last_type == TK_EOF || $last_type == TK_END_COMMAND)) {
        // regexp
        $sep = $c;
        $c = '';
        $esc = false;
        if ($pos < $input_length) {
            while ($esc || $input[$pos] != $sep) {
                $c .= $input[$pos];
                if (!$esc) {
                    $esc = $input[$pos] == '\\';
                } else {
                    $esc = false;
                }
                $pos += 1;
                if ($pos >= $input_length) {
                    break;
                }
            }
        }
        $pos += 1;
        if ($last_type == TK_END_COMMAND) {
            nl();
        }
        return array($sep . $c . $sep, TK_STRING);
    }
    if (in_array($c, $punct)) {
        while ($pos < $input_length and in_array($c . $input[$pos], $punct)) {
            $c .= $input[$pos];
            $pos += 1;
            if ($pos >= $input_length) {
                break;
            }
        }
        return array($c, TK_OPERATOR);
    }
    return array($c, TK_UNKNOWN);
}
Beispiel #8
0
 /**
  * Создаём условие IN для SQL-запроса
  *
  * @param string $param_name - имя параметра
  * @param array $in_values - массив значений
  * @param string $word - IN
  * @return string
  */
 public function make_in($param_name, $in_values = array(), $word = 'IN')
 {
     if (!empty($in_values)) {
         load_lib('array');
         $in_values = make_array($in_values);
         foreach ($in_values as $key => $itm) {
             $in_values[$key] = $this->tosql($itm);
         }
         $res = implode(',', $in_values);
         $res = " {$param_name} {$word} ({$res}) ";
     } else {
         $res = '';
     }
     return $res;
 }
Beispiel #9
0
<?php

set_time_limit(60);
$time_start = microtime(true);
$list = make_array(10000);
$limit = count($list);
for ($i = 0; $i < $limit; $i++) {
    $index = 0;
    while ($index < $limit - $i - 1) {
        if ($list[$index] > $list[$index + 1]) {
            $temp = $list[$index];
            $list[$index] = $list[$index + 1];
            $list[$index + 1] = $temp;
        }
        $index++;
        //var_dump($list);
    }
    //echo "while loop terminated<br>";
}
//var_dump($list);
function make_array($size)
{
    $nums = array();
    for ($x = 0; $x < $size; $x++) {
        $nums[] = rand(0, 10000);
    }
    return $nums;
}
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "<h1>Time taken to sort: " . $time . "</h1>";
Beispiel #10
0
 /**
  *
  * @param c_xml_node $node
  * @param c_xml_node $beforeNode
  * @return c_xml_node
  */
 function insertNodeAfter($node, $afterNode)
 {
     if ($afterNode == null) {
         $this->insertNodeFirst($node);
         return $this;
     }
     $node->parentNode = $this;
     $this->childNodesByName[$node->name] = make_array($this->childNodesByName[$node->name]);
     $num = $this->getNodeNum($afterNode);
     if ($num !== false) {
         array_insert($this->childNodes, $node, $num + 1);
         $this->childNodesByName[$node->name][] = $node;
         //@TODO вставить в массив в нужное место
     }
     return $this;
 }
Beispiel #11
0
<?php

const OFFSET = 0x7fffffffffffffff;
function make_array()
{
    return array_slice(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), OFFSET, OFFSET, true);
}
var_dump(make_array());
Beispiel #12
0
            }
        }
    }
    printf("</TD></TR></TABLE>>");
    if (@$addrto["Dev"] || @$addrto["Role"] || @$addrto["OS"] || @$addrto["children"]) {
        printf("color=beige,style=filled");
    }
    printf("];\n");
}
#draw edges
$edge = array();
# merge traffic between different addresses within the same hosts
# to a single edge
reset($addrs);
while (list($from, $srcv) = each($addrs)) {
    $sql = sprintf("\n    SELECT\n      to_,\n      SUM(bytes)       AS bytes,\n      SUM(bytes_encap) AS bytes_encap,\n      SUM(counter)     AS counter\n    FROM traffic\n    WHERE from_ IN ('%s')\n    AND to_ NOT LIKE '%%.255'\n    GROUP BY to_;", join("','", array_merge(array($from), make_array(@$srcv["children"]))));
    #echo "$sql\n";
    $stmt = $db->query($sql) or die(print_r($db->errorInfo(), 1));
    while (FALSE !== (list($to, $bytes, $encap, $cnt) = $stmt->fetch())) {
        $realto = @$rev[$to];
        if (!$realto) {
            $realto = $to;
        }
        @($edge[$from][$realto] += $encap);
    }
}
echo "/* edges=" . print_r($edge, 1) . "*/";
function colorize($n)
{
    $c = 0xf0 - log($n) / log(2) * 10;
    if ($c < 0) {
Beispiel #13
0
/**
 * Erstellt Formular für DateTime "tt.mm.yy hh:mm:ss"
 */
function makeDateTimeForm($formName, $datetime, $umbruch = true, $class = "")
{
    $datetime = str_replace(".", " ", $datetime);
    $datetime = str_replace(":", " ", $datetime);
    // var_dump($datetime); $datetime = explode(" ", $datetime); var_dump($datetime);
    list($dd, $mm, $yy, $hh, $ii, $ss) = explode(" ", $datetime);
    // echo "tt,mm,yy,hh,ii,ss = $tt,$mm,$yy,$hh,$ii,$ss";
    $selectStr = '<select ';
    if ($class) {
        $selectStr .= 'class="' . $class . '" ';
    }
    $return = $selectStr . 'title="Datum" name="' . $formName . '_d">' . make_option(make_array(1, 31), $dd) . '</select>.';
    $return .= $selectStr . 'title="Datum" name="' . $formName . '_m">' . make_option(make_array(1, 12), $mm) . '</select>.';
    $return .= $selectStr . 'title="Datum" name="' . $formName . '_y">' . make_option(make_array(3, 10), $yy) . '</select>';
    if ($umbruch) {
        $return .= '<br>';
    } else {
        $return .= '&nbsp;';
    }
    $return .= $selectStr . 'title="Uhrzeit" name="' . $formName . '_h">' . make_option(make_array(0, 23), $hh) . '</select>:';
    $return .= $selectStr . 'title="Uhrzeit" name="' . $formName . '_i">' . make_option(make_array(0, 59), $ii) . '</select>:';
    $return .= $selectStr . 'title="Uhrzeit" name="' . $formName . '_s">' . make_option(make_array(0, 59), $ss) . '</select>';
    return $return;
}
Beispiel #14
0
 public function testEmptySuccess()
 {
     $this->assertEquals($this->data, make_array($this->data, ''));
 }