Examveda
Examveda

What will be the output of the following PHP code?
<?php
$number = array(0,1,two,three,four,5);
$num = preg_grep("/[0-5]/", $number);
print_r($num);
?>

A. Array([0]=>0 [1]=>1 [2]=>two [3]=>three [4]=>four [5]=>5)

B. Array([2]=>two [3]=>three [4]=>four)

C. Array([1]=> 1)

D. Array([0]=>0 [1]=>1 [5]=>5)

Answer: Option D

Solution(By Examveda Team)

The preg_grep function is used to search an array for specific patterns and then return a new array based on that filtering.

This Question Belongs to PHP >> Regular Expressions

Join The Discussion

Related Questions on Regular Expressions