array walk in an easy way for displaying view? [Solved] |
[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;
[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"
[eluser]notebook[/eluser]
i am sorry i could'nt understand this concept. does that mean this ? Code: foreach($mydata as $row => $value)
[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.
[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. |
Welcome Guest, Not a member yet? Register Sign In |