]> git.mxchange.org Git - mailer.git/blobdiff - inc/functions.php
bigintval() now casts to double
[mailer.git] / inc / functions.php
index b5071b7d41e7ac2cd0aa384712fbeb09e7ab7477..7857554a5ce86d1bb13e3072cc9062fc5f410941 100644 (file)
@@ -996,7 +996,7 @@ function COMPILE_CODE($code, $simple = false, $constants = true, $full = true) {
                        } // END - if
 
                        // Take all string elements
-                       if (("".bigintval($matches[4][$key])."" != $matches[4][$key]) && (!isset($matchesFound[$key."_".$matches[4][$key]]))) {
+                       if ((is_string($matches[4][$key])) && (!isset($matchesFound[$key."_".$matches[4][$key]]))) {
                                // Replace it in the code
                                $newMatch = str_replace("[".$matches[4][$key]."]", "['".$matches[4][$key]."']", $match);
                                $code = str_replace($match, $newMatch, $code);
@@ -1028,41 +1028,34 @@ function COMPILE_CODE($code, $simple = false, $constants = true, $full = true) {
 function array_pk_sort(&$array, $a_sort, $primary_key = 0, $order = -1, $nums = false)
 {
        $dummy = $array;
-       while ($primary_key < count($a_sort))
-       {
-               foreach ($dummy[$a_sort[$primary_key]] as $key => $value)
-               {
-                       foreach ($dummy[$a_sort[$primary_key]] as $key2 => $value2)
-                       {
+       while ($primary_key < count($a_sort)) {
+               foreach ($dummy[$a_sort[$primary_key]] as $key => $value) {
+                       foreach ($dummy[$a_sort[$primary_key]] as $key2 => $value2) {
                                $match = false;
-                               if (!$nums)
-                               {
+                               if (!$nums) {
                                        // Sort byte-by-byte (also numbers will be interpreted as chars! E.g.: "9" > "10")
                                        if (($key != $key2) && (strcmp(strtolower($dummy[$a_sort[$primary_key]][$key]), strtolower($dummy[$a_sort[$primary_key]][$key2])) == $order)) $match = true;
-                               }
-                                elseif ($key != $key2)
-                               {
+                               } elseif ($key != $key2) {
                                        // Sort numbers (E.g.: 9 < 10)
                                        if (($dummy[$a_sort[$primary_key]][$key] < $dummy[$a_sort[$primary_key]][$key2]) && ($order == -1)) $match = true;
                                        if (($dummy[$a_sort[$primary_key]][$key] > $dummy[$a_sort[$primary_key]][$key2]) && ($order == 1))  $match = true;
                                }
-                               if ($match)
-                               {
+
+                               if ($match) {
                                        // We have found two different values, so let's sort whole array
-                                       foreach ($dummy as $sort_key => $sort_val)
-                                       {
+                                       foreach ($dummy as $sort_key => $sort_val) {
                                                $t                       = $dummy[$sort_key][$key];
                                                $dummy[$sort_key][$key]  = $dummy[$sort_key][$key2];
                                                $dummy[$sort_key][$key2] = $t;
                                                unset($t);
-                                       }
-                               }
-                       }
-               }
+                                       } // END - foreach
+                               } // END - if
+                       } // END - foreach
+               } // END - foreach
 
                // Count one up
                $primary_key++;
-       }
+       } // END - while
 
        // Write back sorted array
        $array = $dummy;
@@ -1245,6 +1238,15 @@ function bigintval($num, $castValue = true) {
        // Filter all numbers out
        $ret = preg_replace("/[^0123456789]/", "", $num);
 
+       // Shall we cast?
+       if ($castValue) $ret = (double)$ret;
+
+       // Has the whole value changed?
+       if ("".$ret."" != "".$num."") {
+               // Log the values
+               DEBUG_LOG(__FUNCTION__.": num={$num},ret={$ret}");
+       } // END - if
+
        // Return result
        return $ret;
 }