menu

PHP Arrays

PHP Arrays - Important Points


11. Which function is used to sort an array in ascending order by value in PHP?

A. sort()

B. asort()

C. ksort()

D. rsort()

Discuss Work Space

Answer: option a

Explanation:

The sort() function is used to sort an array in ascending order by value in PHP.

12. Which function is used to sort an array in descending order by value in PHP?

A. sort()

B. asort()

C. ksort()

D. rsort()

Discuss Work Space

Answer: option d

Explanation:

The rsort() function is used to sort an array in descending order by value in PHP.

13.

What is the output of the following PHP code snippet?

<?php
$array = ["apple", "banana", "orange"];
$lengths = array_map('strlen', $array);
print_r($lengths);
?>

A. ["a", "b", "o"]

B. [5, 6, 6]

C. ["apple", "banana", "orange"]

D. None of the above

Discuss Work Space

Answer: option b

Explanation:

The array_map() function applies a given function to each element of an array, in this case resulting in an array of the lengths of the strings in the original array: [5, 6, 6].

14.

What is the output of the following PHP code snippet?

<?php
$array = ["apple", "banana", "orange"];
$subset = array_slice($array, 1, 2);
print_r($subset);
?>

A. ["apple"]

B. ["banana"]

C. ["orange"]

D. ["banana", "orange"]

Discuss Work Space

Answer: option d

Explanation:

The array_slice() function returns a portion of an array specified by the start and length parameters, in this case resulting in ["banana", "orange"].

15. Which of the following is not a valid way to remove an element from an array in PHP?

A. unset()

B. array_splice()

C. array_remove()

D. array_shift()

Discuss Work Space

Answer: option c

Explanation:

There is no built-in array_remove() function in PHP.


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now