Php finds the sum of all odd items of the following two-dimensional array
PHP中文网用户-7954359
PHP中文网用户-7954359 2023-10-18 15:37:12
0
1
476

$arr2=array(

Array(12,23,34,45),

Array (34,45,67,89),

Array( 56,78,90,1)

)

Is there anyone who knows?



PHP中文网用户-7954359
PHP中文网用户-7954359

reply all(1)
Ray

<?php

$arr2 = array(
    array(12, 23, 34, 45),
    array(34, 45, 67, 89),
    array(56, 78, 90, 1)
);
$sum = 0;
// 遍历
foreach ($arr2 as $subArray) {
     // 遍历
    foreach ($subArray as $value) {
        // 判断奇数项
        if ($value % 2 != 0) {
            $sum += $value;
        }
    }
}
echo $sum;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template