PHP 中多维数组的输出

Output of multidimensional arrays in PHP

我想得到一个array()的最低值。现在我有两个问题:

问题一:无法定义二维数组,出现非法偏移错误

问题 2:当我找到最低值时,我需要知道它是谁。

示例:星期一的值为 5,星期二的值为 8。现在

我需要知道星期一或星期二是否具有最低值,然后我需要该值的工作日。

这是我的代码:

$x = array(  
    ["Monday"]      => array($_REQUEST["Monday"]),
    ["Tuesday"]     => array($_REQUEST["Tuesday"]),
    ["Wednesday"]   => array($_REQUEST["Wednesday"]),
    ["Thursday"]    => array($_REQUEST["Thursday"]),
    ["Friday"]      => array($_REQUEST["Friday"]),
    ["Saturday"]    => array($_REQUEST["Saturday"]),
    ["Sunday"]      => array($_REQUEST["Sunday"])
);

我想你是说你在使用从表单传入的值创建日期名称的数组时遇到问题,你的数组定义有点不对。

这是你想要的吗?

$x = array(  
    "Monday"      => $_REQUEST["Monday"],
    "Tuesday"     => $_REQUEST["Tuesday"],
    "Wednesday"   => $_REQUEST["Wednesday"],
    "Thursday"    => $_REQUEST["Thursday"],
    "Friday"      => $_REQUEST["Friday"],
    "Saturday"    => $_REQUEST["Saturday"],
    "Sunday"      => $_REQUEST["Sunday"]
);

现在求最小值并告诉你那是哪一天

$x = array(  
    "Monday"      => 4,
    "Tuesday"     => 3,
    "Wednesday"   => 2,
    "Thursday"    => 1,
    "Friday"      => 6,
    "Saturday"    => 7,
    "Sunday"      => 8
);

print_r(array_keys($x, min($x))[0]);

结果

Thursday