PHP Arrays Quiz

AdulatoryWildflowerMeadow avatar
AdulatoryWildflowerMeadow
·
·
Download

Start Quiz

Study Flashcards

10 Questions

What does the PHP function array_reverse() do?

Return an array with elements in reversed order

Which PHP function returns the intersection of two arrays?

array_intersect()

What is the output of the PHP array_search() function if the search is successful?

The index where the value is found

How does the PHP function count() differ from array_search()?

count() counts all elements, array_search() searches for a specific value

What is the purpose of the PHP sort() function?

Sort all elements in an array

In PHP, what does the array_chunk() function do?

Divide an array into chunks

How does array_reverse() differ from array_intersect() in PHP?

'Array_reverse()' returns reversed order, 'array_intersect()' returns matching elements.

When using PHP's count() function on an array, what does it return?

The total number of elements in the array

What happens when PHP's array_intersect() is used on two arrays with no matching elements?

'array_intersect()' returns an empty array

'PHP sort() function sorts all the elements' - This statement is:

True

Study Notes

PHP Arrays

  • An array stores multiple values in one single variable.
  • An array is a special variable that can hold more than one value at a time.
  • An array can hold many values under a single name, and values can be accessed by referring to an index number.

Creating an Array in PHP

  • The array() function is used to create an array in PHP.
  • There are three types of arrays in PHP: Indexed, Associative, and Multidimensional arrays.

PHP Indexed Arrays

  • Indexed arrays can be created in two ways: automatic index assignment (index starts at 0) or manual index assignment.
  • Example: $cars = array("Volvo", "BMW", "Toyota"); or $cars[0] = "Volvo"; $cars[1] = "BMW"; $cars[2] = "Toyota";
  • Indexed arrays can be looped through and printed using a for loop.

PHP Associative Arrays

  • Associative arrays use named keys assigned to them.
  • Associative arrays can be created in two ways: using the array() function or by assigning values individually.
  • Example: $age = array("Rohit"=>"23", "Kapil"=>"19", "Neeraj"=>"20"); or $age['Rohit'] = "23"; $age['Kapil'] = "19"; $age['Neeraj'] = "20";
  • Named keys can be used in a script to access values.

PHP Multidimensional Arrays

  • Multidimensional arrays are arrays containing one or more arrays.
  • PHP supports multidimensional arrays that are two, three, four, five, or more levels deep.
  • Multidimensional arrays can be used to store complex data, such as tables.
  • Example: $std = array ( array("Romya", "BCA", 1), array("Madhur", "BCA", 2), ... );
  • Multidimensional arrays can be accessed using row and column indices.

Test your knowledge about PHP arrays. Learn about creating arrays in PHP, indexed arrays, associative arrays, and multidimensional arrays. Practice accessing values in arrays using index numbers or named keys.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Test je basiskennis over PHP met deze quiz!
6 questions
PHP foreach Constructor
3 questions

PHP foreach Constructor

VibrantSuprematism avatar
VibrantSuprematism
PHP Array Iteration Quiz
3 questions
Use Quizgecko on...
Browser
Browser