![]() |
array walk in an easy way for displaying view? [Solved] - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: array walk in an easy way for displaying view? [Solved] (/showthread.php?tid=35958) |
array walk in an easy way for displaying view? [Solved] - El Forum - 11-16-2010 [eluser]notebook[/eluser] In my view i want to display multidimesional array data decently , i want total control over it so that i can show data in a table the way i want. i have these 39 arrays in $mydata in the view. I'll give you an idea with var_dump($mydata) Code: array(39) i tried Code: foreach($mydata as $row) Quote:Message: Trying to get property of non-object then i tried this which worked Code: foreach($mydata as $row) Quote:$row->unit_name; array walk in an easy way for displaying view? [Solved] - El Forum - 11-16-2010 [eluser]Jaketoolson[/eluser] You have an array, not an object. Also, they keys are numerical (0,1,2,etc) which is why $row[0] works and $row['unit_name'] wouldn't. One option would be to dynamically assign the row key's as variables like this. Code: foreach($mydata as $row => $value) "Variable Variables" array walk in an easy way for displaying view? [Solved] - El Forum - 11-16-2010 [eluser]notebook[/eluser] i am sorry i could'nt understand this concept. does that mean this ? Code: foreach($mydata as $row => $value) array walk in an easy way for displaying view? [Solved] - El Forum - 11-16-2010 [eluser]dudeami0[/eluser] Something like this could work: Code: foreach($mydata as $row => $value) { Also, the variable being defined is always on the left, and the value to set is always on the right. array walk in an easy way for displaying view? [Solved] - El Forum - 11-16-2010 [eluser]notebook[/eluser] thanks Jaketoolson and dudeami0 that's working ! array walk in an easy way for displaying view? [Solved] - El Forum - 11-17-2010 [eluser]LinkFox[/eluser] Or make the original array associative. $temp = array( [0] => array('name' => 'value')) Then you can access is with $temp[0]['name'] etc. I prefer this way of doing arrays as its easier for me / other developers to identify the information being accessed in the array. |