Write a PHP program to check if the number of 3's is greater than the number of 5's

  • برمجة بي اتش بي

Write a PHP program to check if the number of 3's is greater than the number of 5's

الأجوبة

<?php
function test($nums)
 { 

    $no_3 = 0;
    $no_5 = 0;

    for ($i = 0; $i < sizeof($nums); $i++)
            {
                if ($nums[$i] == 3) $no_3++;
                if ($nums[$i] == 5) $no_5++;
            }

            return $no_3 > $no_5;
 }   

var_dump(test([1, 5, 6, 9, 3, 3]));
var_dump(test([1, 5, 5, 5, 10, 17]));
var_dump(test([1, 3, 3, 5, 5, 5]));

Sample Output:

bool(true)
bool(false)
bool(false)
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...