CodeIgniter Forums
Multidimensional arrays - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter Archived (from EllisLab) (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Multidimensional arrays (/thread-43315.html)



Multidimensional arrays - El Forum - 07-07-2011

[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


Multidimensional arrays - El Forum - 07-07-2011

[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.


Multidimensional arrays - El Forum - 07-07-2011

[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


Multidimensional arrays - El Forum - 07-07-2011

[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


Multidimensional arrays - El Forum - 07-07-2011

[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()


Multidimensional arrays - El Forum - 07-07-2011

[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.


Multidimensional arrays - El Forum - 07-08-2011

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