21. Write a PHP script to check if a number is a Harshad (Niven) number.

Required Input:

18

Expected Output:

true

Code In Php

<?php function isHarshad($num) { // Your code here } ?>

Run Code?

Click Run Button to view compiled output

22. Create a PHP script to merge two associative arrays and resolve key conflicts.

Required Input:

['a' => 1] + ['a' => 2, 'b' => 3]

Expected Output:

{"a":2,"b":3}

Code In Php

<?php function mergeArrays($arr1, $arr2) { // Your code here } ?>

Run Code?

Click Run Button to view compiled output

23. Write a PHP script to find the longest common prefix of an array of strings.

Required Input:

['flower', 'flow', 'flight']

Expected Output:

fl

Code In Php

<?php function longestCommonPrefix($arr) { // Your code here } ?>

Run Code?

Click Run Button to view compiled output

24. Create a PHP script to find the most frequent element in an array.

Required Input:

[1, 2, 3, 1, 1, 2]

Expected Output:

1

Code In Php

<?php function mostFrequent($arr) { // Your code here } ?>

Run Code?

Click Run Button to view compiled output

25. Write a PHP script to check if a number is a Strong number.

Required Input:

145

Expected Output:

true

Code In Php

<?php function isStrong($num) { // Your code here } ?>

Run Code?

Click Run Button to view compiled output

26. Create a PHP script to implement a basic LRU (Least Recently Used) cache using an array.

Required Input:

["get(1)", "put(2,3)"]

Expected Output:

A

Code In Php

<?php class LRUCache { // Your code here } ?>

Run Code?

Click Run Button to view compiled output

27. Write a PHP script to find the GCD of multiple numbers in an array.

Required Input:

[24, 36, 48]

Expected Output:

12

Code In Php

<?php function gcdArray($arr) { // Your code here } ?>

Run Code?

Click Run Button to view compiled output

28. Create a PHP script to generate a random alphanumeric string of a given length.

Required Input:

5

Expected Output:

A9B3D

Code In Php

<?php function randomString($length) { // Your code here } ?>

Run Code?

Click Run Button to view compiled output

29. Write a PHP script to convert a decimal number to hexadecimal manually.

Required Input:

255

Expected Output:

FF

Code In Php

<?php function decimalToHex($num) { // Your code here } ?>

Run Code?

Click Run Button to view compiled output

30. Create a PHP script to check if a given Sudoku row or column is valid.

Required Input:

[5,3,0,7,9,0,6,0,0]

Expected Output:

true

Code In Php

<?php function isValidSudokuRow($arr) { // Your code here } ?>

Run Code?

Click Run Button to view compiled output

ad vertical

3 of 3