Podcast
Questions and Answers
What does the PHP function array_reverse() do?
What does the PHP function array_reverse() do?
Which PHP function returns the intersection of two arrays?
Which PHP function returns the intersection of two arrays?
What is the output of the PHP array_search() function if the search is successful?
What is the output of the PHP array_search() function if the search is successful?
How does the PHP function count() differ from array_search()?
How does the PHP function count() differ from array_search()?
Signup and view all the answers
What is the purpose of the PHP sort() function?
What is the purpose of the PHP sort() function?
Signup and view all the answers
In PHP, what does the array_chunk() function do?
In PHP, what does the array_chunk() function do?
Signup and view all the answers
How does array_reverse() differ from array_intersect() in PHP?
How does array_reverse() differ from array_intersect() in PHP?
Signup and view all the answers
When using PHP's count() function on an array, what does it return?
When using PHP's count() function on an array, what does it return?
Signup and view all the answers
What happens when PHP's array_intersect() is used on two arrays with no matching elements?
What happens when PHP's array_intersect() is used on two arrays with no matching elements?
Signup and view all the answers
'PHP sort() function sorts all the elements' - This statement is:
'PHP sort() function sorts all the elements' - This statement is:
Signup and view all the answers
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.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
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.