wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Strings and Arrays

Total questions: 13

Worksheet time: 13mins

Name
Class
Date
1.

In PHP the _______    function returns the total number of characters in a string.

a)

len()

b)

str_length()

c)

length()

d)

strlen()

2.

In PHP the __________ function is used to find out whether some text occurs within a string.

a)

strstr()  

b)

find()

c)

count()

d)

str_find()

3.

 In PHP the __________ function finds the last match in the string, rather than the first

a)

strpos()

b)

str_last()

c)

 strrpos()

d)

strpos_last()

4.

Which of the following is not a Built-in String functions in php?

a)

strlen()

b)

str_replace()

c)

strpos()

d)

strreverse()

5.

Which of the following is the output of the below code?

<?php echo strpos("Hello letsfindcourse!", "lets"), " \n"; ?>

a)

4

b)

5

c)

6

d)

7

6.

Predict the output of the following code snippet :

<?php $str="chess was played"; echo strlen(substr($str,3,2))." " ?>

a)

1

b)

2

c)

null

d)

3

7.

Arrays with named keys in PHP are called ________

a)

Associative arrays 

b)

Indexed arrays 

c)

Multidimensional arrays 

d)

named arrays

8.

 The _____ function is used to sort associative arrays in descending order, according to the key in PHP.

a)

arsort()

b)

krsort() 

c)

ksort()

d)

sort()

9.

 The _____ function removes the first element from the start of an array in PHP.

a)

array_shift() 

b)

array_pop() 

c)

array_push()

d)

array_unshift() 

10.

 In PHP the _____ function adds one or more new elements to the end of an array.

a)

array_unshift() 

b)

array_push()

c)

array_shift() 

d)

array_pop() 

11.

Which of the following are correct ways of creating an array? i) state[0] = "karnataka"; ii) $state[] = array("karnataka"); iii) $state[0] = "karnataka"; iv) $state = array("karnataka");

a)

iii) and iv)

b)

ii) and iii)

c)

Only i)

d)

ii), iii) and iv)

12.

Key/value pair can be initialized using => operator?

a)

True

b)

False

c)

Depend on program

d)

Keys does not exist in array

13.

In PHP the __________ function is used to find out whether some text occurs within a string.

a)

strstr()  

b)

find()

c)

count()

d)

str_find()