0

I have an array as follows using var_dump

array(26) {
  ["SUPPLIER_NAME"]=>
  string(14) ""Company Ltd""
  ["INACTIVATE"]=>
  string(13) ""Keep Active""
  ["SUPPLIER_INACTIVE_DATE"]=>
  string(0) ""
  ["SITE_INACTIVE_DATE"]=>
  string(0) ""
  ["ADDRESS2"]=>
  string(0) ""
  ["ADDRESS3"]=>
  string(0) ""
}

However when I try and do the following, it's blank, no value returns

echo $array["SUPPLIER_NAME"]

When I do any other key, it works, just not on SUPPLIER_NAME

Any ideas?

EDITED

We consume an array as follows (I'm just referencing the first key in this array):

echo '<pre>';
var_dump($result[0]);
echo '</pre>';

This produces:

array(26) {
  ["SUPPLIER_NAME"]=>
  string(14) ""Company Ltd""
  ["SUPPLIER_TYPE"]=>
  string(13) ""Keep Active""
...
...
  ["ADDRESS2"]=>
  string(0) ""
  ["ADDRESS3"]=>
  string(0) ""
}

I then try and do the following which spits out nothing:

echo '<pre>';
print_r($result[0]["SUPPLIER_NAME"]);
echo '</pre>';

However, this produces the correct data (and every other key works as well):

echo '<pre>';
print_r($result[0]["SUPPLIER_TYPE"]);
echo '</pre>';

I did the following:

echo '<pre>';
var_dump(array_keys($result[0]));
echo '</pre>';

I got:

array(26) {
  [0]=>
  string(16) "SUPPLIER_NAME"
pee2pee
  • 3,619
  • 7
  • 52
  • 133
  • 1
    can we see full code block relating to this.. at the moment this can't be reproduced, we can only guess. Also, CAPITALS IN PROGRAMMING IS NOT FUN TO READ! Use lowercase - much nicer on the eyes – treyBake Jul 01 '19 at 13:56
  • 1
    You probably have some invisible characters *somewhere*. Either in your code trying to access `$array["SUPPLIER_NAME"]`, or in the actual array. Try `var_dump(array_keys($array))` for starters… – deceze Jul 01 '19 at 13:59
  • Copy&pasting your debug output out from above into a hex editor shows that you have a Byte Order Mark (hex `ef bb bf`) preceding the `SUPPLIER_NAME`. – 04FS Jul 01 '19 at 13:59
  • @deceze there is one. – Cid Jul 01 '19 at 13:59
  • 1
    If this is from a CSV file, then check for BOM (https://stackoverflow.com/questions/32184933/remove-bom-%C3%AF-from-imported-csv-file) – Nigel Ren Jul 01 '19 at 14:00
  • Ah ok, Thanks all, how would I amend the key name to remove these given I don't control the data I receive? – pee2pee Jul 01 '19 at 14:12
  • Where does the data come from at all? Use `echo urlencode(array_keys($result[0])[0])` to see what weird bytes you're dealing with exactly… – deceze Jul 01 '19 at 14:13

1 Answers1

1

There is an hidden character in your array :

array(26) {
//  v---------------------- there
  ["SUPPLIER_NAME"]=>
  string(14) ""Company Ltd""
  ["INACTIVATE"]=>
  string(13) ""Keep Active""
  ["SUPPLIER_INACTIVE_DATE"]=>
  string(0) ""
  ["SITE_INACTIVE_DATE"]=>
  string(0) ""
  ["ADDRESS2"]=>
  string(0) ""
  ["ADDRESS3"]=>
  string(0) ""
}

"SUPPLIER_NAME" != "SUPPLIER_NAME"
Cid
  • 14,968
  • 4
  • 30
  • 45