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 )
Â
⇒Understanding PHP Arrays and Their Basic Operations
⇒⇒PHP Tutorials
2017-02-03, 3362👍, 0💬
Popular Posts:
What Is HTML? HTML (HyperText Markup Language) is the standard markup language for creating Web page...
Where to get the detailed description of the json_encode() Function in PHP? Here is the detailed des...
How To Control Padding Spaces within a Table Cell? Cell padding spaces are spaces between cell inner...
Where Is the Submitted Form Data Stored in PHP? When a user submit a form on your Web server, user e...
Can You Add Values to an Array without Keys in PHP? Can You Add Values to an Array with a Key? The a...