Created
June 10, 2010 10:37
-
-
Save aaronmcadam/432808 to your computer and use it in GitHub Desktop.
bookordersystem array manipulation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//EXAMPLE CODE FROM MY BOOK PROJECT: | |
$data = array(); | |
foreach ($entries->rows as $index=>$e) { | |
if(array_key_exists('title', $e['value'])){ | |
// checking if the id of the book has already been met | |
if ( isset($data[$e['id']]) ) { | |
$d = $data[$e['id']]; | |
} | |
else{ | |
$d = array(); | |
$d["title"] = $e['value']['title']; | |
$d["date"] = $e['value']['date']; | |
$d["cover"] = $e['value']['cover']; | |
$d["detail"] = $e['value']['detail']; | |
$d["orderedOn"] = isset( $e['value']['orderedOn'] ) ? $e['value']['orderedOn'] : NULL; | |
$d["bookId"] = $e['id']; | |
$d["orders"] = array(); | |
} | |
} | |
if ( array_key_exists('message', $e['value']) ) { | |
if ( $d["bookId"] === $e['value']['book'] ) { | |
array_push($d['orders'], array('user' => $e['value']['user'], 'message' => $e['value']['message'])); | |
} | |
} | |
$data[$d['bookId']] = $d; | |
} | |
$array = $data; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment