How to find the largest and smallest number in a 2-dimensional array of 6x7?

0
  

for each row of the two-dimensional array that prints the largest number and for each column the smallest number

<?php

$array=array("uno"=>array("1"=>rand(1,300),
                             "2"=>rand(1,300),
                             "3"=>rand(1,300),
                             "4"=>rand(1,300),
                             "5"=>rand(1,300),
                             "6"=>rand(1,300),
                             "7"=>rand(1,300)),


                "dos"=>array("1"=>rand(1,300),
                             "2"=>rand(1,300),
                             "3"=>rand(1,300),
                             "4"=>rand(1,300),
                             "5"=>rand(1,300),
                             "6"=>rand(1,300),
                             "7"=>rand(1,300)),

               "tres"=>array("1"=>rand(1,300),
                             "2"=>rand(1,300),
                             "3"=>rand(1,300),
                             "4"=>rand(1,300),
                             "5"=>rand(1,300),
                             "6"=>rand(1,300),
                             "7"=>rand(1,300)),

               "cuatro"=>array("1"=>rand(1,300),
                             "2"=>rand(1,300),
                             "3"=>rand(1,300),
                             "4"=>rand(1,300),
                             "5"=>rand(1,300),
                             "6"=>rand(1,300),
                             "7"=>rand(1,300)),
              "cinco"=>array("1"=>rand(1,300),
                             "2"=>rand(1,300),
                             "3"=>rand(1,300),
                             "4"=>rand(1,300),
                             "5"=>rand(1,300),
                             "6"=>rand(1,300),
                             "7"=>rand(1,300)),

               "seis"=>array("1"=>rand(1,300),
                             "2"=>rand(1,300),
                             "3"=>rand(1,300),
                             "4"=>rand(1,300),
                             "5"=>rand(1,300),
                             "6"=>rand(1,300),
                             "7"=>rand(1,300)));

<?
    
asked by Omar Anthony Huamani Garcia 09.10.2018 в 05:24
source

1 answer

0

As Jonathan told you, it is good to write the problem on paper and try to make a pseudo-code to have a clearer solution.
Anyway, I would probably use array_column instead.

foreach($array as $key => $subarray){
    $vals = array_column($subarray, $key)
    $min = min($vals);
    $max = max($vals);
}

and so you could get the lowest and highest of each one.
I have not tried the code with your array, but I feel that the index to be a String ("1", "2" ...) may give you problems.
In the case of a problem with that index in String, you would have to go through each list and compare each value with the other.
I hope that what I already showed you will help you solve the problem of your task.

    
answered by 12.10.2018 в 23:14