Extra Variables in the For Loop
4 years ago
4 years ago
#1
Hello, In the Controller $data = $this->newspapers->get_all_orders(); $data['meta_title'] = 'Page Title'; $this->template('dashboard', $data); I do a for loop on $data in the view file. I see two extra variables in the for loop. The two extra variables are due to the meta_title and template being passed into $data. How can I skip these in the loop? Thanks
4 years ago
#2
Andrew you can delete them from the array just before you loop through them See these threads ========== https://stackoverflow.com/questions/369602/deleting-an-element-from-an-array-in-php ========== https://www.w3docs.com/snippets/php/how-to-delete-an-element-from-an-array-in-php.html =============================. Or you should put the variables into a new array and then loop throught == Dan
4 years ago
#3
Dan is kind of correct here. I wouldn't unset any elements in the $data array, I would however add the 'newspaper' rows returned by 'get_all_orders()' into their own array inside of $data like so: then loop through each row
4 years ago
#4
Setting a new array for the rows is perfect!! Thank you both!!