Advertisement
WILDAN_IZZUDIN

LOOPING INCLUDE FUNCTION 2 WAYS

Oct 26th, 2019
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. <?php
  2. error_reporting(0);
  3.  
  4. // fungsi include + data array (jika ada)
  5. function render($n, $data = []) {
  6.     return include_once $n . '.php';
  7. }
  8.  
  9. // menghapus spasi dia antara koma
  10. function nospace($n) {
  11.     $n = str_replace(", ", ",", $n);
  12.     $n = str_replace(" ,", ",", $n);
  13.         return $n;
  14. }
  15.  
  16. // fungsi looping + include + data array (jika ada)
  17. function loopinc($file, $data = []) {
  18.     $include = explode(',', nospace($file));
  19.     $loop = count($include) - 1;
  20. for ($i=0; $i <= $loop; $i++) {
  21.     @render($include[$i], $data);
  22.     }
  23. }
  24.  
  25. Class loop {
  26. public static function inc($file = array(), $data) {
  27.     foreach ($file as $files) {
  28.         include_once $files.'.php';
  29.         }
  30.     }
  31. }
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement