note 98567 modified in function.json-decode by danbrown

From: Date: Fri, 25 Jun 2010 15:12:20 +0000
Subject: note 98567 modified in function.json-decode by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170436@lists.php.net to get a copy of this message
I was getting an array like: Array ( [COLUMNS] => Array ( [0] => ID [1] => FIRST [2] => LAST ) [DATA] => Array ( [0] => Array ( [0] => 10 [1] => Mary [2] => Smith ) [1] => Array ( [0] => 11 [1] => Joe [2] => Black ) [2] => Array ( [0] => 12 [1] => Tom [2] => Green ) [3] => Array . . . With lots more columns and data from a json_decode call to a Cold Fusion .cfc which returned a database query. This is easy to turn into a nice associative array with the following code: <?php foreach ($results['DATA'] as $rowcount => $row){ foreach ($row as $colcount => $col){ $lines[$rowcount][$results['COLUMNS'][$colcount]]=$col; } } ?> to get: Array ( [0] => Array ( [ID] => 10 [FIRST] => Mary [LAST] => Smith ) [1] => Array ( [ID] => 11 [FIRST] => Joe [LAST] => Black ) . . . etc. I hope this helps someone. --was-- I was getting an array like: Array ( [COLUMNS] => Array ( [0] => ID [1] => FIRST [2] => LAST ) [DATA] => Array ( [0] => Array ( [0] => 10 [1] => Mary [2] => Smith ) [1] => Array ( [0] => 11 [1] => Joe [2] => Black ) [2] => Array ( [0] => 12 [1] => Tom [2] => Green ) [3] => Array . . . With lots more columns and data from a json_decode call to a Cold Fusion .cfc which returned a database query. This is easy to turn into a nice associative array with the following code: foreach ($results['DATA'] as $rowcount => $row){ foreach ($row as $colcount => $col){ $lines[$rowcount][$results['COLUMNS'][$colcount]]=$col; } } to get: Array ( [0] => Array ( [ID] => 10 [FIRST] => Mary [LAST] => Smith ) [1] => Array ( [ID] => 11 [FIRST] => Joe [LAST] => Black ) . . . etc. I hope this helps someone. http://php.net/manual/en/function.json-decode.php

« previous php.notes (#170436) next »