I have a php array, $vararray, like so
[var1] => 1
[var2] => 1
[var3] => 1
[var4] => 1
[var5] => 2
[var6] => 2
[var7] => 1
[var8] => 1
After a bunch of operations i get a key/index of var8. How do I get value of var8 using the key? I can get the key using array key function. But is there a function for array value? I checked php manual but didnt seem to find any.
You can access it like this:
Or you can loop over the array using a
foreach
loop: http://php.net/manual/en/control-structures.foreach.phpAccessible like this
If
$key
contains the key you're interested in (e.g.var8
) you useto access the value of the corresponding element.
For getting all keys value like
$var1
,$var2
,$var3
, .... Try this