I’m trying to complete my assignment and this is the last thing to do now.
I know if I want to print the whole array I can just use foreach and many different method to print the entire array
foreach($v as $k=>$variable_name) { echo "<p> This is index of $k. value is $variable_name <br/></p>";}
But what if I want to only print each index separately?
I want to do the error message under each form so that is why I want each of them separate.
I tried with $v[0] and nothing appear.
is there a trick or something am I missing?
If you’re talking about an associative array, you need to fetch the index directly:
Example:
You can do a print_r($array) to see the array structure nicely formatted:
What you’re doing instead is fetch a value by its numerical index, like in
On a further note, you can check beforehand if a key exists using array_key_exists():