这段代码演示了PHP数组的强大功能,关联数组的创建和使用,PHP中的关联数组和python中的字典非常类似
/**
* PHP关联数组使用范例演示
*
* @param
* @arrange 512-笔记网: jb51.cc
**/
/* First method to associate create array. */
$salaries = array(
"mohammad" => 2000,"qadir" => 1000,"zara" => 500
);
echo "Salary of mohammad is ". $salaries['mohammad'] . "<br />";
echo "Salary of qadir is ". $salaries['qadir']. "<br />";
echo "Salary of zara is ". $salaries['zara']. "<br />";
/* Second method to create array. */
$salaries['mohammad'] = "high";
$salaries['qadir'] = "medium";
$salaries['zara'] = "low";
echo "Salary of mohammad is ". $salaries['mohammad'] . "<br />";
echo "Salary of qadir is ". $salaries['qadir']. "<br />";
echo "Salary of zara is ". $salaries['zara']. "<br />";
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
输出结果如下: Salary of mohammad is 2000 Salary of qadir is 1000 Salary of zara is 500 Salary of mohammad is high Salary of qadir is medium Salary of zara is low 原文链接:https://www.f2er.com/php/528287.html