Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $results = array(
- array(
- 'id' => 0,
- 'key' => 'somekey',
- 'value' => 'This is a string.'
- ),
- array(
- 'id' => 0,
- 'key' => 'someotherkey',
- 'value' => 100002
- ),
- array(
- 'id' => 1,
- 'key' => 'someotherkey',
- 'value' => 100002
- ),
- array(
- 'id' => 2,
- 'key' => 'somekey',
- 'value' => 'This is another string'
- ),
- array(
- 'id' => 2,
- 'key' => 'someotherkey',
- 'value' => 100002
- ),
- ); //This is like what you get from MySQL. Each array is a result from the database.
- $crosstab = array();
- foreach($results as $result) {
- if(!is_array($crosstab[$result['key']]) {
- $crosstab[$result['key']] = array();
- }
- $crosstab[$result['key']][$result[id]] = $result['value'];
- }
- var_dump($crosstab);
Add Comment
Please, Sign In to add comment