I am using API data in a model which is passed through to a controller then to view. In one particular instance I need to do a foreach() loop but in javascript to get the data I need, please see below how I've done it.
I know this is bad practice but wanted to know what the best practice is to achieve this so I know going forward.
categories: [<?php foreach($champ_name as $champ_id => $stat_value) {
foreach ($stat_value as $cn => $cs) {
if($champ_id != 0) {
echo '"'.$cn.'",';
}
}
} ?>]
Thanks for looking/helping.
(PS. the above does work but I know is not the right way)