Problem with PHP array index.
- by user632027
Following code:
<?php
$test_array = array();
$test_array['string_index'] = "data in string index";
$test_array[] = "data in index 0";
$test_array[] = "data in index 1";
$test_array[] = "data in index 2";
foreach($test_array as $key => $val)
{
if($key != 'string_index')
{
echo $val."<br>";
}
}
?>
gives result:
data in index 1
data in index 2
Question is - where is "data in index 0"??? How to get elements from numeric indices 0-n?
Also if I change 'string_index' to something else which doesn't exist, it echoes everything except [0]. Plz, explain me this.
Thnx in advance