i am working on a php code to display d3js histogram,
// Coerce types.
bins.forEach(function(bin) {
bin.Income = +bin.Income;
bin.People = +bin.People;
});
// Normalize each bin to so that height = quantity/width;
// see http://en.wikipedia.org/wiki/Histogram#Examples
for (var i = 1, n = bins.length, bin; i < n; i++) {
bin = bins[i];
bin.offset = bins[i - 1].Income;
bin.width = bin.Income - bin.offset;
bin.height = bin.People / bin.width;
}
for reference, http://bl.ocks.org/mbostock/1624660
my data, instead of "Income" and "people" has "bs" and "cs". in the sample output the format in which the data comes is [object Array] i made my data in the similar way. in the above code, where income and people called, are from the $key. for me, it returns the following output.
Array ( [0] => {"0":"26.5","1":"80"} [1] => {"0":" 27","1":" 222"}
[2] => {"0":"27.5","1":" 303"}
[3] => {"0":" 28","1":" 408"}
[4] => {"0":" 28.5","1":" 276"}
[5] => {"0":" 29","1":" 151"}
[6] => {"0":" 29.5","1":null} )
this was got from a simple foreach loop,
$object = new stdClass();
foreach ($map[$l] as $key => $value)
{
$object->$key = $value;
}
print_r($object);
by default, this $key is assigning "0" and "1" to each object itself. i want to call these objects using '$key' variable in some other part of my code. since it is "0" and "1", i am unable to call it. is there any way to assign the names "bs" to "0" and "cs" to "1" in the output array so that it displays,
Array ( [0] => {"bs":"26.5","cs":"80"} [1] => {"bs":" 27","cs":" 222"}
[2] => {"bs":"27.5","cs":" 303"}
[3] => {"bs":" 28","cs":" 408"}
[4] => {"bs":" 28.5","cs":" 276"}
[5] => {"bs":" 29","cs":" 151"}
[6] => {"bs":" 29.5","cs":null} )
thanks in advance.