Skip to content

Instantly share code, notes, and snippets.

@olimortimer
Last active January 4, 2016 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olimortimer/8687279 to your computer and use it in GitHub Desktop.
Save olimortimer/8687279 to your computer and use it in GitHub Desktop.
PHP > JS Functions
<?php
$data = array();
foreach ($products as $product) {
$data[$product->make][$product->variant.' - '.$product->material][] = $product;
}
var data = {};
for (var i = 0; i < result.rows.length; i++) {
var product = result.rows.item(i);
var title = product.variant+' - '+product.material;
// Check if the object exists; create it if not
if(product.make in data == false) {
data[product.make] = {};
}
// Check if the array exists; create it if not
if(title in data[product.make] == false) {
data[product.make][title] = [];
}
data[product.make][title].push(product);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment