Search code examples
phparraysmultidimensional-arrayarray-column

array_column not working for an array of objects?


This is my current array structure:

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"
    }
  }
}

Every time I run array_column for max_weight I get an empty array as a result. I'm supposed to use the returned array for max(). Is there a workaround for this?


Solution

  • v7.0.0: Added the ability for the input parameter to be an array of objects.

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