Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
What Types of Data Can Be Used as Array Keys
What Types of Data Can Be Used as Array Keys? - PHP Script Tips - Understanding PHP Arrays and Their Basic Operations
✍: FYIcenter.com
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[""] = Basic
Note that an empty string can also be used as a key.
2007-04-14, 4627👍, 0💬
Popular Posts:
How To Set session.gc_maxlifetime Properly? - PHP Script Tips - Understanding and Using Sessions As ...
What’ is the sequence in which ASP.NET events are processed ? Following is the sequence in which the...
How To Delete All Rows a Table? - MySQL FAQs - Understanding SQL INSERT, UPDATE and DELETE Statement...
What’s the difference between Unit testing, Assembly testing and Regression testing? Unit testing is...
How To Compare Two Strings with strcmp()? - PHP Script Tips - PHP Built-in Functions for Strings PHP...