Examveda
Examveda

What will be the output of the following PHP code?
<?php
$foods = array("pasta", "steak", "fish", "potatoes");
$food = preg_grep("/^s/", $foods);
print_r($food);
?>

A. Array ( [0] => pasta [1] => steak [2] => fish [3] => potatoes )

B. Array ( [3] => potatoes )

C. Array ( [1] => steak )

D. Array ( [0] => potatoes )

Answer: Option C

Solution(By Examveda Team)

This function is used to search an array for foods beginning with s.

This Question Belongs to PHP >> Regular Expressions

Join The Discussion

Related Questions on Regular Expressions