function condensing

not sure what to title this,

Ok I am not very good with php I have a very basic understanding how some of it works, I had taken a bit of code from someone and modified it to better suit what I was after for plucking from the script. Currently I have it working for what I need but I am looking to better code it and get more information from less coding.

[php]public function get_latest_map_usage($response_object = null){
global $latest_day;
global $latest_date_value;
if($response_object == null){
if($this->last_response != null && isset($this->last_response->teams)){
// We shouldn’t have team for map data so this is wrong
return null;
else {
$response_object = $this->last_response;
if (isset($response_object->teams))
return null;
$latest_date = null;
$latest_day = null;
$latest_date_value = 0;
$todate = date(“Y-m-d”, strtotime(“0 days”));
foreach ($response_object as $date => $value){
if($date == $todate){
$latest_date = $date;
$latest_date_change = new DateTime($latest_date);
$latest_day = $latest_date_change->format(‘F j Y’);
$latest_date_value = $value;
return array(“date” => $latest_date, “value” => $latest_date_value);

So I am pulling info off a json file and separating all the info in the array plucking specific dates and the values for those dates by way of specifying the date i’m after using the strotime and backing it off -1,-2 ect for each date. What I am currently doing now to get all the specific days i need plucked is recreating that same function for each date i want to pluck. I would much rather be able to have one function do everything by using variables such as $latest_date[-1], $latest_date[-2] as opposed to how I’m doing it now.

I had also set the variables global so I can pull the data into another script because I don’t know how to format the return array to dump itself into two separate variables within the other script.

The json file has data for a whole month as date => value and ultimately I would like to be able to script to add up a weeks worth of totals and a months worth of totals as well as list individual day totals as well.

thanks for any help!

Sponsor our Newsletter | Privacy Policy | Terms of Service