Heim  >  Artikel  >  Backend-Entwicklung  >  php中将变量转换为数组的函数应用

php中将变量转换为数组的函数应用

WBOY
WBOYOriginal
2016-07-25 09:02:541056Durchsuche
  1. //给定变量
  2. $city = "菏泽";
  3. $province = "山东省";
  4. $project = "PHP Program";
  5. $location_vars = array("province", "city");
  6. //创建数组
  7. $result = compact("project", "nothing", "location_vars");
  8. print_r($result);
  9. ?>
复制代码

在以上的程序中,因为并不存在名字是"nothing"的变量,因此程序的输出结果如下: Array ( [project] => PHP Program [province] => 山东省 [city] => 菏泽 )



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn