-4

$element is the array below:

Array
(
    [Order ID] => 352383060
    [Ordered Date] => 18/02/2022 11:59:00 PM
    [SKU] => 
    [Product] => (Kitchware)Transaction fee for 18/02/2022
    [Name] =>  
    [Quantity] => 1
    [Price (Per Unit)] => 0.00
    [Total Shipping] => 0.00
    [Total Sale Price] => 0.00
    [Commission Fee] => 1.09
    [Net Amount] => -1.09
    [Original Order ID] => 
    [InvoiceRef] => ART5sa924
    [Misc Reference] => 
    [Order Group No] => 
)

Yet when I attempt $import2xero_csv_array[1][15] = $element['Order ID']

I get the error:

Notice: Undefined index: Order ID in /opt/lampp/htdocs/mydeal-join-columns.php on line 132

I thought there might be some invisible characters in the index Order ID but it's not clear that there is. Perhaps a different type of whitespace?

Any ideas?

Edit: yes, I loop through the array and there are multiple arrays. The full array data is:

    array(6) {
          [0]=>
          array(15) {
            ["Order ID"]=>
            string(9) "347640060"
            ["Ordered Date"]=>
            string(21) "1/02/2022 11:59:00 PM"
            ["SKU"]=>
            string(0) ""
            ["Product"]=>
            string(47) "(Kitchware)Transaction fee for 01/02/2022"
            ["Name"]=>
            string(1) " "
            ["Quantity"]=>
            string(1) "1"
            ["Price (Per Unit)"]=>
            string(4) "0.00"
            ["Total Shipping"]=>
            string(4) "0.00"
            ["Total Sale Price"]=>
            string(4) "0.00"
            ["Commission Fee"]=>
            string(4) "1.09"
            ["Net Amount"]=>
            string(5) "-1.09"
            ["Original Order ID"]=>
            string(0) ""
            ["InvoiceRef"]=>
            string(9) "ART586504"
            ["Misc Reference"]=>
            string(0) ""
            ["Order Group No"]=>
            string(0) ""
          }
          [1]=>
          array(15) {
            ["Order ID"]=>
            string(9) "348513440"
            ["Ordered Date"]=>
            string(21) "4/02/2022 11:59:00 PM"
            ["SKU"]=>
            string(0) ""
            ["Product"]=>
            string(47) "(Kitchware)Transaction fee for 04/02/2022"
            ["Name"]=>
            string(1) " "
            ["Quantity"]=>
            string(1) "1"
            ["Price (Per Unit)"]=>
            string(4) "0.00"
            ["Total Shipping"]=>
            string(4) "0.00"
            ["Total Sale Price"]=>
            string(4) "0.00"
            ["Commission Fee"]=>
            string(4) "3.27"
            ["Net Amount"]=>
            string(5) "-3.27"
            ["Original Order ID"]=>
            string(0) ""
            ["InvoiceRef"]=>
            string(9) "ART586504"
            ["Misc Reference"]=>
            string(0) ""
            ["Order Group No"]=>
            string(0) ""
          }
          [2]=>
          array(15) {
            ["Order ID"]=>
            string(9) "348748260"
            ["Ordered Date"]=>
            string(21) "5/02/2022 11:59:00 PM"
            ["SKU"]=>
            string(0) ""
            ["Product"]=>
            string(47) "(Kitchware)Transaction fee for 05/02/2022"
            ["Name"]=>
            string(1) " "
            ["Quantity"]=>
            string(1) "1"
            ["Price (Per Unit)"]=>
            string(4) "0.00"
            ["Total Shipping"]=>
            string(4) "0.00"
            ["Total Sale Price"]=>
            string(4) "0.00"
            ["Commission Fee"]=>
            string(4) "1.09"
            ["Net Amount"]=>
            string(5) "-1.09"
            ["Original Order ID"]=>
            string(0) ""
            ["InvoiceRef"]=>
            string(9) "ART586504"
            ["Misc Reference"]=>
            string(0) ""
            ["Order Group No"]=>
            string(0) ""
          }
          [3]=>
          array(15) {
            ["Order ID"]=>
            string(9) "349326620"
            ["Ordered Date"]=>
            string(21) "7/02/2022 11:59:00 PM"
            ["SKU"]=>
            string(0) ""
            ["Product"]=>
            string(47) "(Kitchware)Transaction fee for 07/02/2022"
            ["Name"]=>
            string(1) " "
            ["Quantity"]=>
            string(1) "1"
            ["Price (Per Unit)"]=>
            string(4) "0.00"
            ["Total Shipping"]=>
            string(4) "0.00"
            ["Total Sale Price"]=>
            string(4) "0.00"
            ["Commission Fee"]=>
            string(4) "1.09"
            ["Net Amount"]=>
            string(5) "-1.09"
            ["Original Order ID"]=>
            string(0) ""
            ["InvoiceRef"]=>
            string(9) "ART586504"
            ["Misc Reference"]=>
            string(0) ""
            ["Order Group No"]=>
            string(0) ""
          }
          [4]=>
          array(15) {
            ["Order ID"]=>
            string(9) "350883660"
            ["Ordered Date"]=>
            string(22) "13/02/2022 11:59:00 PM"
            ["SKU"]=>
            string(0) ""
            ["Product"]=>
            string(47) "(Kitchware)Transaction fee for 13/02/2022"
            ["Name"]=>
            string(1) " "
            ["Quantity"]=>
            string(1) "1"
            ["Price (Per Unit)"]=>
            string(4) "0.00"
            ["Total Shipping"]=>
            string(4) "0.00"
            ["Total Sale Price"]=>
            string(4) "0.00"
            ["Commission Fee"]=>
            string(4) "1.09"
            ["Net Amount"]=>
            string(5) "-1.09"
            ["Original Order ID"]=>
            string(0) ""
            ["InvoiceRef"]=>
            string(9) "ART586504"
            ["Misc Reference"]=>
            string(0) ""
            ["Order Group No"]=>
            string(0) ""
          }
          [5]=>
          array(15) {
            ["Order ID"]=>
            string(9) "351815280"
            ["Ordered Date"]=>
            string(22) "16/02/2022 11:59:00 PM"
            ["SKU"]=>
            string(0) ""
            ["Product"]=>
            string(47) "(Kitchware)Transaction fee for 16/02/2022"
            ["Name"]=>
            string(1) " "
            ["Quantity"]=>
            string(1) "1"
            ["Price (Per Unit)"]=>
            string(4) "0.00"
            ["Total Shipping"]=>
            string(4) "0.00"
            ["Total Sale Price"]=>
            string(4) "0.00"
            ["Commission Fee"]=>
            string(4) "1.09"
            ["Net Amount"]=>
            string(5) "-1.09"
            ["Original Order ID"]=>
            string(0) ""
            ["InvoiceRef"]=>
            string(9) "ART586504"
            ["Misc Reference"]=>
            string(0) ""
            ["Order Group No"]=>
            string(0) ""
          }
        }
    
    


array(1) {
  [0]=>
  array(15) {
    ["Order ID"]=>
    string(9) "352383060"
    ["Ordered Date"]=>
    string(22) "18/02/2022 11:59:00 PM"
    ["SKU"]=>
    string(0) ""
    ["Product"]=>
    string(47) "(Kitchware)Transaction fee for 18/02/2022"
    ["Name"]=>
    string(1) " "
    ["Quantity"]=>
    string(1) "1"
    ["Price (Per Unit)"]=>
    string(4) "0.00"
    ["Total Shipping"]=>
    string(4) "0.00"
    ["Total Sale Price"]=>
    string(4) "0.00"
    ["Commission Fee"]=>
    string(4) "1.09"
    ["Net Amount"]=>
    string(5) "-1.09"
    ["Original Order ID"]=>
    string(0) ""
    ["InvoiceRef"]=>
    string(9) "ART587924"
    ["Misc Reference"]=>
    string(0) ""
    ["Order Group No"]=>
    string(0) ""
  }
}

    array(4) {
      [0]=>
      array(15) {
        ["Order ID"]=>
        string(9) "348321980"
        ["Ordered Date"]=>
        string(21) "4/02/2022 12:35:58 PM"
        ["SKU"]=>
        string(9) "URO-GG141"
        ["Product"]=>
        string(62) "Vogue Polyester Insulated Food Delivery Bag Large (From) GG141"
        ["Name"]=>
        string(10) "Jan Martin"
        ["Quantity"]=>
        string(1) "1"
        ["Price (Per Unit)"]=>
        string(5) "88.00"
        ["Total Shipping"]=>
        string(5) "35.00"
        ["Total Sale Price"]=>
        string(6) "123.00"
        ["Commission Fee"]=>
        string(5) "13.53"
        ["Net Amount"]=>
        string(6) "109.47"
        ["Original Order ID"]=>
        string(0) ""
        ["InvoiceRef"]=>
        string(9) "ART591265"
        ["Misc Reference"]=>
        string(0) ""
        ["Order Group No"]=>
        string(9) "343023080"
      }
      [1]=>
      array(15) {
        ["Order ID"]=>
        string(9) "348324300"
        ["Ordered Date"]=>
        string(21) "4/02/2022 12:43:36 PM"
        ["SKU"]=>
        string(9) "URO-CS754"
        ["Product"]=>
        string(73) "Vogue Stainless Steel Heavy Duty Non-Stick 1/1 Gastronorm Tray 40mm CS754"
        ["Name"]=>
        string(17) "Brendan Gillespie"
        ["Quantity"]=>
        string(1) "1"
        ["Price (Per Unit)"]=>
        string(6) "107.00"
        ["Total Shipping"]=>
        string(5) "35.00"
        ["Total Sale Price"]=>
        string(6) "142.00"
        ["Commission Fee"]=>
        string(5) "15.62"
        ["Net Amount"]=>
        string(6) "126.38"
        ["Original Order ID"]=>
        string(0) ""
        ["InvoiceRef"]=>
        string(9) "ART591265"
        ["Misc Reference"]=>
        string(0) ""
        ["Order Group No"]=>
        string(9) "343023134"
      }
      [2]=>
      array(15) {
        ["Order ID"]=>
        string(9) "348459600"
        ["Ordered Date"]=>
        string(20) "4/02/2022 8:50:06 PM"
        ["SKU"]=>
        string(8) "URO-U821"
        ["Product"]=>
        string(64) "Olympia Whiteware Cream & Milk Jugs 305ml (Pack of 6 from) U821"
        ["Name"]=>
        string(12) "Wendy Flavel"
        ["Quantity"]=>
        string(1) "1"
        ["Price (Per Unit)"]=>
        string(5) "64.00"
        ["Total Shipping"]=>
        string(5) "35.00"
        ["Total Sale Price"]=>
        string(5) "99.00"
        ["Commission Fee"]=>
        string(5) "10.89"
        ["Net Amount"]=>
        string(5) "88.11"
        ["Original Order ID"]=>
        string(0) ""
        ["InvoiceRef"]=>
        string(9) "ART591265"
        ["Misc Reference"]=>
        string(0) ""
        ["Order Group No"]=>
        string(9) "343027086"
      }
      [3]=>
      array(15) {
        ["Order ID"]=>
        string(9) "348587540"
        ["Ordered Date"]=>
        string(20) "5/02/2022 1:10:44 PM"
        ["SKU"]=>
        string(9) "URO-GF737"
        ["Product"]=>
        string(74) "Olympia Bar Collection Sherry / Port Glasses 120ml (Pack of 6 from) GF737"
        ["Name"]=>
        string(13) "Clive W Roach"
        ["Quantity"]=>
        string(1) "1"
        ["Price (Per Unit)"]=>
        string(5) "36.00"
        ["Total Shipping"]=>
        string(5) "35.00"
        ["Total Sale Price"]=>
        string(5) "71.00"
        ["Commission Fee"]=>
        string(4) "7.81"
        ["Net Amount"]=>
        string(5) "63.19"
        ["Original Order ID"]=>
        string(0) ""
        ["InvoiceRef"]=>
        string(9) "ART591265"
        ["Misc Reference"]=>
        string(0) ""
        ["Order Group No"]=>
        string(9) "343030441"
      }
    }
shau
  • 1
  • 3
  • 1
    That's the only element you show in your question, or do you execute this with a loop that has multiple "element"s? Also it would help if you showed how `$element` is defined. Specifically is it an object or associative array. – mardubbles Jun 04 '22 at 06:12
  • 1
    If element[0] works this means the key is incorrect else script is wrong. – JoelCrypto Jun 04 '22 at 06:15
  • 1
    If you want to check for invisible or multibyte characters, `var_dump()` your data instead of `print_r()` . We cannot reproduce your problem with the provided details. This question must be closed. – mickmackusa Jun 04 '22 at 06:16
  • I have appended the full array data to the original post. This should answer all your questions. – shau Jun 04 '22 at 06:36
  • 1
    Even tho you were already closed, I will note that *this does not answer all questions* because you show a data structure still, and no relevant source code to debug. .... In your "edit" you even show a different data structure (a multi-dimensioned array) with no explanation of how "element" comes into play. – mardubbles Jun 04 '22 at 06:49
  • You are right. However, I think I may have found the problem. Preliminary testing shows that it may have nothing to do with the code or the array. Does it make sense to you if the csv file was UT8-BOM instead of UT8 encoding, that indices with spaces in them could be problematic? – shau Jun 04 '22 at 07:29
  • 1
    A common problem is that a CSV starts with a BOM and so the first label (if a header is present) gets the BOM at the start. https://stackoverflow.com/questions/32184933/remove-bom-%C3%AF-from-imported-csv-file should help in removing it. – Nigel Ren Jun 04 '22 at 07:59

0 Answers0