Q:

Write a PHP program to check a specified number is present in a given array of integers

0

Write a PHP program to check a specified number is present in a given array of integers.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
function test($nums, $n)
{
    if (in_array($n, $nums))
    return true;
    
    return false;
 }

var_dump(test(array(1,2,9,3), 3));
var_dump(test(array(1,2,2,3), 2));
var_dump(test(array(1,2,2,3), 9));

Sample Output:

bool(true)
bool(true)
bool(false)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now