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, ≈13🔥, 0💬
Popular Posts:
Where to find tutorials on RSS specifications? I want to learn it to describe my API services. Here ...
How to use the JSON to XML Conversion Tool at utilities-online.info? If you want to try the JSON to ...
How To Truncate an Array in PHP? If you want to remove a chunk of values from an array, you can use ...
How to view API details on the Publisher Dashboard of an Azure API Management Service? You can follo...
How To Merge Cells in a Column? If you want to merge multiple cells vertically in a row, you need to...