divideinto.php 948 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. *
  4. * Function code for the matrix division operation
  5. *
  6. * @copyright Copyright (c) 2013-2018 Mark Baker (https://github.com/MarkBaker/PHPMatrix)
  7. * @license https://opensource.org/licenses/MIT MIT
  8. */
  9. namespace Matrix;
  10. use Matrix\Operators\Division;
  11. /**
  12. * Divides two or more matrix numbers
  13. *
  14. * @param array of string|integer|float|Matrix $matrixValues The numbers to divide
  15. * @return Matrix
  16. */
  17. function divideinto(...$matrixValues)
  18. {
  19. if (count($matrixValues) < 2) {
  20. throw new \Exception('This function requires at least 2 arguments');
  21. }
  22. $matrixValues = array_reverse($matrixValues);
  23. $matrix = array_shift($matrixValues);
  24. if (!is_object($matrix) || !($matrix instanceof Matrix)) {
  25. $matrix = new Matrix($matrix);
  26. }
  27. $result = new Division($matrix);
  28. foreach ($matrixValues as $matrix) {
  29. $result->execute($matrix);
  30. }
  31. return $result->result();
  32. }