Last active
January 4, 2016 22:19
-
-
Save olimortimer/8687279 to your computer and use it in GitHub Desktop.
PHP > JS Functions
This file contains 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
<?php | |
$data = array(); | |
foreach ($products as $product) { | |
$data[$product->make][$product->variant.' - '.$product->material][] = $product; | |
} |
This file contains 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
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