]> git.nbdom.net Git - nb.git/commitdiff
good night
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 1 Mar 2016 02:47:51 +0000 (02:47 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 1 Mar 2016 02:47:51 +0000 (02:47 +0000)
lib/php/functions.php

index 97dc5cc8690ba7d81a7274665cae1fa5c96ff237..debec6bc6d183120e8c967870b2f15ff88588076 100644 (file)
@@ -63,7 +63,7 @@ function ls_dir($path,$recurse=false,$exp='') {
 
 }
 
-function ar_first($ar) { return $ar[0]; }
+function ar_first($ar) { return is_array($ar) and count($ar) ? $ar[0] : false; }
 
 function ar_map($return,$array,$as_hash=false) {
   $map = array_map(create_function('$a',"return($return);"),$array);
@@ -226,9 +226,47 @@ function html_select_array($data,$opt=array()) {
   return $html;
 
 }
-    /*
-    if (preg_match('/^(1)?$/',$this->db->p('header'))) echo $this->{"rows_begin_$format"}($this->fields());
-      echo $this->{"rows_rec_$format"}($row);
-    echo $this->{"rows_end_$format"}($opt);
+/*
+  Add missing functions for compatibility
 */
+if (!function_exists('array_replace_recursive')) {
+       # http://php.net/manual/en/function.array-replace-recursive.php
+  function array_replace_recursive($array, $array1) {
+    function recurse($array, $array1) {
+      foreach ($array1 as $key => $value) {
+
+        // create new key in $array, if it is empty or not an array
+        if (!isset($array[$key]) || (isset($array[$key]) && !is_array($array[$key]))) {
+          $array[$key] = array();
+        }
+        // overwrite the value in the base array
+        if (is_array($value)) {
+          $value = recurse($array[$key], $value);
+        }
+
+        $array[$key] = $value;
+
+      }
+
+      return $array;
+    }
+    // handle the arguments, merge one by one
+    $args = func_get_args();
+    $array = $args[0];
+
+    if (!is_array($array)) {
+      return $array;
+    }
+
+    for ($i = 1; $i < count($args); $i++) {
+      if (is_array($args[$i])) {
+        $array = recurse($array, $args[$i]);
+      }
+    }
+
+    return $array;
+  }
+}
 ?>