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 )
⇐ Index of Array Values in PHP
2017-02-03, 10953🔥, 0💬
Popular Posts:
How To Read a File in Binary Mode in PHP? If you have a file that stores binary data, like an execut...
How to install "C++/CLI Support" component in Visual Studio? I need to build my Visual Studio C++/CL...
How To Open Standard Output as a File Handle in PHP? If you want to open the standard output as a fi...
How to reinstall npm with a node version manager? I am getting permission errors with the current ve...
How To Remove Slashes on Submitted Input Values in PHP? By default, when input values are submitted ...