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:
Can You Add Values to an Array without a Key
Can You Add Values to an Array without a Key? - PHP Script Tips - Understanding PHP Arrays and Their Basic Operations
✍: FYIcenter.com
Can You Add Values to an Array with a Key? The answer is yes and no. The answer is yes, because you can add values without specifying any keys. The answer is no, because PHP will add a default integer key for you if you are not specifying a key. PHP follows these rules to assign you the default keys:
Here is a PHP example script:
<?php
$mixed = array();
$mixed["Zero"] = "PHP";
$mixed[1] = "Perl";
$mixed["Two"] = "Java";
$mixed["3"] = "C+";
$mixed[""] = "Basic";
$mixed[] = "Pascal";
$mixed[] = "FORTRAN";
print("Array with default keys:\n");
print_r($mixed);
?>
This script will print:
Array with default keys:
Array
(
[Zero] => PHP
[1] => Perl
[Two] => Java
[3] => C+
[] => Basic
[4] => Pascal
[5] => FORTRAN
)
2007-04-20, 5409👍, 0💬
Popular Posts:
How can we implement singleton pattern in .NET? Singleton pattern mainly focuses on having one and o...
What CLASSPATH Settings Are Needed to Run JUnit? It doesn't matter if you run your JUnit tests from ...
What will happen in these three cases? if (a=0) { //somecode } if (a==0) { //do something } if (a===...
What is the purpose of Replication ? Replication is way of keeping data synchronized in multiple dat...
How To Use SELECT Statement to Count the Number of Rows? - Oracle DBA FAQ - Understanding SQL SELECT...