Skip to content

Instantly share code, notes, and snippets.

@aaronmcadam
Created June 10, 2010 10:37
Show Gist options
  • Save aaronmcadam/432808 to your computer and use it in GitHub Desktop.
Save aaronmcadam/432808 to your computer and use it in GitHub Desktop.
bookordersystem array manipulation
//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