Welcome Guest, Not a member yet? Register   Sign In
Multidimensional arrays
#1

[eluser]Todlerone[/eluser]
Hello again and TY in advance for any help/suggestions. I'm trying to create a multimensional array and to this point I haven't needed to. I have tried this but it doesn't work.
Code:
foreach ($pstatus as $ps):
                $cvnum= $ps['clinic_visit_id'];
                $treatplan = $this->Fractions_model->get_treatandplan_where($cvnum);
                foreach ($treatplan as $tp):
                    if ($ps['plans_plan_name'] == $tp['plans_plan_name']){
                        foreach ($data['regions'] as $r):
                            if ($tp['treat_region'] == $r['name']){
                                $data["total_".$r['name']."_treats"] += 1;
                                $monthNUM = date("m", strtotime($ps['plan_status_started_plan_date']));
                                $data['courseMONTH']=[$monthNUM][$r['name']] +=1;
                            }
                        endforeach;
                    }
                endforeach;
endforeach;

I'm trying to create courseMONTH array.

TY
#2

[eluser]Mirge[/eluser]
$data['courseMONTH']=[$monthNUM][$r['name']] +=1;

is plain wrong.. haven't looked at your loops to check logic, but I know that's throwing a syntax error.
#3

[eluser]Todlerone[/eluser]
I went with this and it seems to work.
Code:
$courseMONTH[$monthNUM][$r['name']] +=1;

Could I just do this to pass to the view?

Code:
$data['courseMONTH'] = $courseMONTH[$monthNUM][$r['name']]

TY
#4

[eluser]Todlerone[/eluser]
Hello again...I can't seem to see the problem with this but I keep getting the error
Invalid argument supplied for foreach()
. It occurs on the line with
Code:
foreach ($treatplan as $tp):

Code:
foreach ($pstatus as $ps):
                $cvnum= $ps['clinic_visit_id'];
                $treatplan = $this->Fractions_model->get_treatandplan_where($cvnum);
                foreach ($treatplan as $tp):
                    if ($ps['plans_plan_name'] == $tp['plans_plan_name']){
                        foreach ($data['regions'] as $r):
                            if ($tp['treat_region'] == $r['name']){
                                $data["total_".$r['name']."_treats"] += 1;
                                $monthNUM = date("m", strtotime($ps['plan_status_started_plan_date']));
                                $yearNUM = date("y", strtotime($ps['plan_status_started_plan_date']));
                                $courseMONTH[$monthNUM.$yearNUM][$r['name']] +=1;
                            }
                        endforeach;
                    }
                endforeach;
            endforeach;

I get the result I want but I also get the warning????

TY
#5

[eluser]jmadsen[/eluser]
Code:
$treatplan = $this->Fractions_model->get_treatandplan_where($cvnum);

is not getting any data back for some reason.

Check your query or whatever logic is in get_treatandplan_where()
#6

[eluser]Jaketoolson[/eluser]
case sensitive multidimensional arrays especially with the Key's containing both upper and lowercase makes me want to barf...

Just break down your logic into a simple method of creating multidimensional arrays with numbers and letters. When you create a method that gives you the end results you desire, just reverse engineer it back into your existing method.
#7

[eluser]Todlerone[/eluser]
Works great now ty




Theme © iAndrew 2016 - Forum software by © MyBB