When dealing with PHP
array
s, I quite often here terms such as:
Array
Key
,
Array
Index
,
Array
Element
,
Array
Value
Can someone, PLEASE , in simple terms explain what each of these basically means?
Is there any difference?... are they all referring to the same thing?
Where do you use which? and when?
Any clarification with some simple use case examples will be highly appreciated.
i.e: in an array like: array($a,$b,$c,$d=>$e)
What will be What?
Thanks in advance.
An array is a collection of Elements.
Every element has key & value. Key can be a integer(index) or a string.
In you case
array($a, $b, $c, $d=>$e)
can be rewritten as
array(0 => $a, 1 => $b, 2 => $c, $d => $e);
Where 0, 1, 2, $d are the keys of the array.
You can refer 0, 1, 2 as a index for value $a,$b,$c respectively and $d is a key for $e.
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With