据我目前所知,这个内置函数主要作用是 可以让你的代码更清晰,节省代码量 我们先看一下正常的写法: $name = "鱼"; $age = "10086"; $sex = "保密"; $phone = "10010"; $result['name'] = $name; $result['age'] = $age; $result['sex'] = $sex; $result['phone'] = $phone; dump($result); 这个是 用compact的写法: $name = "鱼"; $age = "10086"; $sex = "保密"; $phone = "10010"; $result = compact("name","age","sex","phone");//注意:参数为你定义的变量名 不对应将无法获取 dump($result);
array(4) { ["name"] => string(3) "鱼" ["age"] => string(5) "10086" ["sex"] => string(6) "保密" ["phone"] => string(5) "10010" }
|
|