Skip to content

Instantly share code, notes, and snippets.

@Cyken-Zeraux
Last active August 29, 2015 14:13
Show Gist options
  • Save Cyken-Zeraux/dd7577d284c5977f3c50 to your computer and use it in GitHub Desktop.
Save Cyken-Zeraux/dd7577d284c5977f3c50 to your computer and use it in GitHub Desktop.
example data naming
function afunction($array) {
//does some processing
return $array;
}
//Data to be trimmed
$dataarray0 = array("foobar", "This\n");
$dataarray1 = array("Cybran", "is\n\n\n\n");
$dataarray2 = array("UEF", "an");
$dataarray3 = array("Seraphim", "example");
$dataarray4 = array("Honkeys", " ");
//2D array container (actually has above data dynamically inputted, not static).
$x = array(array("This\n", "1"), array("is\n\n\n\n", "2"), array("an", "6"), array("example", "9"), array(" , "));
$i = 0;
//Loops with 2D array count and processes original variables back into another 2D array.
$Aarray = array();
for ($y = 0; $y < count($x); $y++) {
$Aarray[] = array(${"dataarray$y"}[0], afunction(${"dataarray$y"}));
}
$JSONoutput = json_encode(
array("Dataset" => $Aarray)
);
echo $JSONoutput;
//output:
//{"Dataset":[["foobar",["foobar","This\n"]],
//["Cybran",["Cybran","is\n\n\n\n"]],
//["UEF",["UEF","an"]],
//["Seraphim",["Seraphim","example"]],
//["Honkeys",["Honkeys"," "]]
//]}
//wanted output:
//{"Dataset":["foobar",["foobar","This\n"],
//"Cybran",["Cybran","is\n\n\n\n"],
//"UEF",["UEF","an"],
//"Seraphim",["Seraphim","example"],
//"Honkeys",["Honkeys"," "]
//]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment