-3

actually i dont understand why i get no access to the values of a array.

if i print a array i get this result

print_r($e)

    Array
    (
        [FIELDNAME1] => MYTEXT
        [FIELDNAME2] => MYTEXT2
    )

now i want to access the field directly with

  echo"Element 0".$e[0]."<br>";
  echo"Element 1".$e[1]."<br>";

Under $e[0] and $e[1] I get no response (empty/nothing).

Why I can't get access to $e[0] etc.?

Is there any way to get access with 0/1/2... for this array, background is that i dont know the names of the elements, so i have to access with 1 and 2.

newbieRB
  • 137
  • 1
  • 14
  • The indexes are not `0`, `1`. They are `FIELDNAME1` & `FIELDNAME2`. Try `$e['FIELDNAME2']` – Sougata Bose Mar 15 '17 at 09:56
  • Is there any way to get access with 0/1/2... for this array, background is that i dont know the names of the elements, so i have to access with 1 and 2. – newbieRB Mar 15 '17 at 11:54

2 Answers2

1

Because your array is associative. You'd access values by their associated key:

echo"Element 0".$e['FIELDNAME1']."<br>";
echo"Element 1".$e['FIELDNAME2']."<br>";
jensgram
  • 31,109
  • 6
  • 81
  • 98
0

That's because you have an associative array here, where the array keys are FIELDNAME1 and FIELDNAME2 and not 0, 1 like you stated.

This will work:

echo"Element 0".$e['FIELDNAME1']."<br>";
echo"Element 1".$e['FIELDNAME2']."<br>";

Or if you want to loop through your array, try this:

foreach ($e as $k => $v) {
    echo "Element $k : ".$v."<br>";
}
Indrasis Datta
  • 8,692
  • 2
  • 14
  • 32