0

I have the following nested array where I am trying to convert index [1] of every nested from a hex value to ascii. I've already got a function that does the conversion perfectly when I reference them one at a time but when I try to traverse it in a for loop I get nothing in my output log file.

Here's the array:

Array
(
    [0] => Array
        (
            [0] => E2007C84D20119B16F6FD066
            [1] => 37373535303931383400000000000000
            [2] => 9/7/2016 10:42:51 PM
            [3] => -57
            [4] => 1
        )

    [1] => Array
        (
            [0] => E2007C84D200ABB16F6FCEAE
            [1] => 37363835303032323000000000000000
            [2] => 9/7/2016 10:42:51 PM
            [3] => -62
            [4] => 1
        )

    [2] => Array
        (
            [0] => E2007C84D20133316F6FD0CC
            [1] => 37373335313834323400000000000000
            [2] => 9/7/2016 10:42:52 PM
            [3] => -52
            [4] => 1
        )

    [3] => Array
        (
            [0] => E2007C84D2008B716F6FCE2D
            [1] => 37363930303032383400000000000000
            [2] => 9/7/2016 10:42:54 PM
            [3] => -58
            [4] => 2
        )

    [4] => Array
        (
            [0] => E2007C84D200D3316F6FCF4C
            [1] => 37373335313534343300000000000000
            [2] => 9/7/2016 10:42:54 PM
            [3] => -52
            [4] => 1
        )

    [5] => Array
        (
            [0] => E2007C84D2006C316F6FCDB0
            [1] => 37373630303032303600000000000000
            [2] => 9/7/2016 10:42:54 PM
            [3] => -54
            [4] => 1
        )

    [6] => Array
        (
            [0] => E2007C84D1544EF16F6E753B
            [1] => 37373230393131333800000000000000
            [2] => 9/7/2016 10:42:57 PM
            [3] => -62
            [4] => 2
        )    
)

And here's the for loop I've been trying:

for each ($dataArray[0] as $dataItem) {

    $dataItem[1] = hex2str($dataItem[1]);
}

PHP arrays always give me trouble.

Jahzin
  • 1
  • 2
  • *"I get nothing in my output log file"* are you outputting `$dataArray` or `$dataItem`. remember that `$dataItem` only exists within the context of the loop and the data in `$dataArray` is unchanged when you go `$dataItem[1] = hex2str($dataItem[1]);` – Memor-X Sep 08 '16 at 00:10
  • See: http://stackoverflow.com/q/2270303/3933332 – Rizier123 Sep 08 '16 at 00:10

0 Answers0