Tools, FAQ, Tutorials:
Adding Values to an Array without Keys in PHP
Can You Add Values to an Array without Keys in PHP?
✍: 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 )
2017-02-03, 1970👍, 0💬
Popular Posts:
How to add an API to an API product for internal testing on the Publisher Portal of an Azure API Man...
How to extend json.JSONEncoder class? I want to encode other Python data types to JSON. If you encod...
Where to find tutorials on OpenID? Here is a large collection of tutorials to answer many frequently...
How To Upload Files into Database in PHP? To store uploaded files to MySQL database, you can use the...
What is EPUB 3.0 Metadata "dc:publisher" and "dc:rights" elements? EPUB 3.0 Metadata "dc:publisher" ...