📜  如何在 php 代码示例中编写 laravel dd 函数

📅  最后修改于: 2022-03-11 14:53:39.176000             🧑  作者: Mango

代码示例1
function d($data){
    if(is_null($data)){
        $str = "NULL";
    }elseif($data == ""){
        $str = "Empty";
    }elseif(is_array($data)){
        if(count($data) == 0){
            $str = "Empty array.";
        }else{
            $str = "";
            foreach ($data as $key => $value) {
                $str .= "";
            }
            $str .= "
" . $key . "" . d($value) . "
"; } }elseif(is_resource($data)){ while($arr = mysql_fetch_array($data)){ $data_array[] = $arr; } $str = d($data_array); }elseif(is_object($data)){ $str = d(get_object_vars($data)); }elseif(is_bool($data)){ $str = "" . ($data ? "True" : "False") . ""; }else{ $str = $data; $str = preg_replace("/\n/", "
\n", $str); } return $str; } function dnl($data){ echo d($data) . "
\n"; } function dd($data){ echo dnl($data); exit; } function ddt($message = ""){ echo "[" . date("Y/m/d H:i:s") . "]" . $message . "
\n"; }