Workshop

Quiz

1: Which construct can you use to define an array?
2: What is the index number of the last element of the array defined here?
$users = array ("Harry", "Bob", "Sandy");
3: Without using a function, what would be the easiest way of adding the element "Susan" to the $users array defined previously?
4: Which function could you use to add the string "Susan" to the $users array?
5: How would you find out the number of elements in an array?
6: How would you loop through an array?
7: Which function would you use to merge two arrays?
8: How would you sort an associative array by its keys?

Answers

A1: You can create an array with the array() construct.
A2: The last element is $users[2]. Remember that arrays are indexed from zero by ...

Get Sams Teach Yourself PHP in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.