Exemple #1
0
 public static function tableFromArray($array, $id = NULL, $class = NULL)
 {
     self::$_buffer = "<table id=\\'{$id}\\' class=\\'{$class}\\' >" . PHP_EOL;
     if (!is_indexed($array)) {
         $keys = array_keys($array);
     }
 }
Exemple #2
0
function lime_export($var)
{
    if (is_array($var)) {
        $i = is_indexed($var);
        $out = array();
        foreach ($var as $k => $v) {
            $out[] = (!$i ? lime_export($k) . ' => ' : '') . lime_export($v);
        }
        $result = 'array(' . PHP_EOL . preg_replace('~^~m', INDENT, implode(',' . PHP_EOL, $out)) . PHP_EOL . ')';
    } elseif (is_int($var) || is_float($var)) {
        $result = (string) $var;
    } elseif (is_string($var)) {
        $opt1 = '\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $var) . '\'';
        $opt2 = $opt1;
        if (strpos($var, '$') === false) {
            $opt2 = '"' . str_replace(array('\\', '"'), array('\\\\', '\\"'), $var) . '"';
        }
        if (strlen($opt1) <= strlen($opt2)) {
            $result = $opt1;
        } else {
            $result = $opt2;
        }
    } elseif (is_bool($var)) {
        $result = $var ? 'true' : 'false';
    } else {
        bug('Wrong type: ' . gettype($var));
    }
    return $result;
}
Exemple #3
0
function update_array_to_array(array $array_to_be_update, array $destination_array)
{
    if (!is_assoc($array_to_be_update) && !is_assoc($destination_array)) {
        if (is_indexed($array_to_be_update) && is_indexed($destination_array)) {
            foreach ($array_to_be_update as $updatevalue) {
                if (!in_array($updatevalue, $destination_array)) {
                    $destination_array[] = $updatevalue;
                }
            }
        } else {
            foreach ($array_to_be_update as $updatekey => $updatevalue) {
                if (!array_key_exists($updatekey, $destination_array)) {
                    $destination_array[$updatekey] = $updatevalue;
                } else {
                    $destination_array[$updatekey] += $updatevalue;
                }
            }
        }
    } else {
        foreach ($array_to_be_update as $updatekey => $updatevalue) {
            ${$updatekey . "s"} = explode(",", $updatevalue);
            foreach (${$updatekey . "s"} as ${$updatekey}) {
                if (array_key_exists($updatekey, $destination_array)) {
                    if (!in_array(${$updatekey}, explode(",", $destination_array[$updatekey]))) {
                        $destination_array[$updatekey] .= "," . ${$updatekey};
                    }
                } else {
                    $destination_array[$updatekey] = $array_to_be_update[$updatekey];
                }
            }
        }
    }
    return $destination_array;
}