1

这是我当前的数组结构:

array(2) {
  ["Ground"] => array(4) {
    [0] => object(Shipping\Model\Shipping)#337 (5) {
      ["shipping_id"] => NULL
      ["min_weight"] => string(4) "0.00"
      ["max_weight"] => string(4) "5.00"
      ["shipping_method"] => string(6) "Ground"
      ["shipping_rate"] => string(4) "8.00"
    }
    [1] => object(Shipping\Model\Shipping)#385 (5) {
      ["shipping_id"] => NULL
      ["min_weight"] => string(4) "6.00"
      ["max_weight"] => string(5) "10.00"
      ["shipping_method"] => string(6) "Ground"
      ["shipping_rate"] => string(5) "12.00"
    }
  }
  ["Expedited"] => array(4) {
    [0] => object(Shipping\Model\Shipping)#388 (5) {
      ["shipping_id"] => NULL
      ["min_weight"] => string(4) "0.00"
      ["max_weight"] => string(4) "5.00"
      ["shipping_method"] => string(9) "Expedited"
      ["shipping_rate"] => string(5) "12.00"
    }
  }
}

每次我运行时array_columnmax_weight我都会得到一个空数组。我应该将返回的数组用于max(). 有解决方法吗?

4

2 回答 2

3

v7.0.0:添加了输入参数为对象数组的功能。

来源:https ://secure.php.net/manual/en/function.array-column.php

于 2018-01-10T00:03:14.570 回答
1

array_columnPHP 7 中对我来说工作正常。这是一个例子......

<?php
$shippingMethods = array("Ground" => array());

$gMethod = new stdClass();
$gMethod->shipping_id = NULL;
$gMethod->min_weight = "0.00";
$gMethod->max_weight = "5.00";
$gMethod->shipping_method = "Ground";
$gMethod->shipping_rate = "8.00";

$shippingMethods["Ground"][] = $gMethod;

$gMethod = new stdClass();
$gMethod->shipping_id = NULL;
$gMethod->min_weight = "6.00";
$gMethod->max_weight = "10.00";
$gMethod->shipping_method = "Ground";
$gMethod->shipping_rate = "12.00";

$shippingMethods["Ground"][] = $gMethod;

$shippingMethod = "Ground";
$result = max(array_column(($shippingMethods[$shippingMethod]), "max_weight"));

echo $result;
?>
于 2018-01-10T00:10:32.970 回答