我是 php 新手并尝试使用地图数组。我希望我$arr2
持有不同类型水果的价值。但是当我执行以下代码时,它告诉我"apple"
是一个未定义的索引。你能告诉我如何更正以下代码,以便我可以访问不同的值吗?
<?php
main_fun ();
function main_fun ()
{
$arr2 = array();
num2_data ($arr2);
echo "<br>.".$arr2["apple"]["q1"]; // quadrant 1 value of apple
echo "<br>.".$arr2["orange"]["q2"]; // quadrant 2 value of orange
}
function num2_data (&$arr2)
{
$arr2 = array("apple" => array("q1" => 1.1380711874577, "q2" => 1.7625118400083, "q3" => 1.8957417329238, "q4" => 2.4453545524829));
$arr2 = array("orange" => array("q1" => 1.1380711874577, "q2" => 2.5045795667914, "q3" => 1.8957417329238, "q4" => 2.7192512120757));
}
?>