PHP

Topic: Arrays

What Types of Data Can Be Used as Array Keys?

Two types of data can be used as array keys: string and integer. When a string is used as a key and the string represent an integer, PHP will convert the string into a integer and use it as the key. Here is a PHP script on different types of keys:<?php $mixed = array();$mixed["Zero"] = "PHP";$mixed[1] = "Perl";$mixed["Two"] = "Java";$mixed["3"] = "C+";$mixed[""] = "Basic";print("Array with mixed keys:\n");print_r($mixed);print("\$mixed[3] = ".$mixed[3]."\n");print("\$mixed[\"3\"] = ".$mixed["3"]."\n");print("\$mixed[\"\"] = ".$mixed[""]."\n");?>This script will print:Array with mixed keys:Array(    [Zero] => PHP    [1] => Perl    [Two] => Java    [3] => C+    [] => Basic)$mixed[3] = C+$mixed["3"] = C+$mixed[""] = BasicNote that an empty string can also be used as a key.

Browse random answers:

How To Create an Array?
How To Test If a Variable Is an Array?
How To Retrieve Values out of an Array?
What Types of Data Can Be Used as Array Keys?
How Values in Arrays Are Indexed?
Can You Add Values to an Array without Keys?
Can You Copy an Array?
How to Loop through an Array?
How the Values Are Ordered in an Array?
How To Copy Array Values to a List of Variables?
How To Get the Total Number of Values in an Array?
How Do You Know If a Key Is Defined in an Array?
How To Find a Specific Value in an Array?
How To Get All the Keys Out of an Array?
How To Get All the Values Out of an Array?
How To Sort an Array by Keys?
How To Sort an Array by Values?
How To Join a List of Keys with a List of Values into an Array?
How To Merge Values of Two Arrays into a Single Array?
How To Use an Array as a Queue?
How To Use an Array as a Stack?
How To Randomly Retrieve a Value from an Array?
How To Create an Array with a Sequence of Integers or Characters?
How To Pad an Array with the Same Value Multiple Times?
How To Truncate an Array?
How To Join Multiple Strings Stored in an Array into a Single String?
How To Split a String into an Array of Substring?
How To Get the Minimum or Maximum Value of an Array?
How can we know the count/number of elements of an array?
How can we know the total number of elements of Array?
Explain Creating and Naming an Array.
What are the different functions in sorting an array?
What are the different functions in sorting an array?
How come the code works, but doesn’t for two-dimensional array of mine? 
What are super global arrays?
Arrays in PHP?