all in order: №1
$arr1 = []; for ($i=0; $i<10; $i++){ $arr1[$i] = mt_rand(0,10); } random 10 arrays are created here with random values.
$arr2=[]; for($i=0; $i<10; $i++) { $arr2[$i]= []; for($j=0; $j<$arr1[$i]; $j++){ $arr2[$i][$j]=mt_rand(0, 10); } } here arrays are created from the elements of the first array further: №3
$max=$min = $arr2[0]; for ($i=0; $i<10; $i++){ if($max < $arr2[$i]){ $max = $arr2[$i]; } if ($min > $arr2[$i]){ $min = $arr2[$i]; } } print_r($max); print_r($min); I find the maximum and minimum values from array No. 2: here is the output from two arrays:
Array (
[0] => 2
[1] => 9
[2] => 6
[3] => 5
[4] => 1
[5] => 9
[6] => 5
[7] => 2
[8] => 5
)
Array
(
[0] => 0
[1] => 1
now you need to add all the numbers from the second array min:
$min = $arr2[0]; $sum = 0; for ($i=0; $i<10; $i++){ if($min > $arr2[$i]){ $min = $arr2[$i]; } #$sum += $arr2[$i]; } #echo $sum; ! ) Fatal error: Uncaught Error: Unsupported operand types
tell me how to correctly calculate the elements of this array
$minis an array, then obviously$sum =0; foreach($min as $v) $sum += $v$sum =0; foreach($min as $v) $sum += $v; For some reason, you add up not the minima butarr2[i], although these are arrays themselves and cannot be added to the number. - teran