Problem with PHP array index.
Posted
by
user632027
on Stack Overflow
See other posts from Stack Overflow
or by user632027
Published on 2011-02-26T15:11:52Z
Indexed on
2011/02/26
15:25 UTC
Read the original article
Hit count: 144
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
© Stack Overflow or respective owner