php - codeigniter don't get the right value using for loop -
i'm struggling getting right values in of loop.
here data pass controller view
$data['moisstring'] = $moisstring; //result of var_dump var_dump($data['moisstring'] ); array (size=3) 0 => string 'janvier' (length=7) 1 => string 'février' (length=8) 2 => string 'mars' (length=4) $data['year'] = $year; //result of var_dump var_dump($data['year'] ); array (size=3) 0 => int 2014 1 => int 2014 2 => int 2014
in view have form_dropdown , want obtain like:
**************** * janvier 2014 * * février 2014 * * mars 2014 * ****************
here view:
echo form_open('suivrepaiement/view', 'method="get"'); $month = array(); $annee = array(); ($i = 0; $i < count($moisstring); $i++) { $month[] = $moisstring[$i]; $annee[]= $year[$i]; foreach ($fichefrais $mois) { $options[$mois->mois] = $month[$i]." ".$annee[$i]; } } echo form_dropdown('mois', $options, $this->input->get('mois'), 'class="btn btn-default dropdown-toggle"'); echo form_hidden('visiteur', set_value('visiteur', $this->input->get('visiteur'))); echo form_submit('', 'envoyer', 'class="btn btn-info"'); echo form_close();
but get:
************* * mars 2014 * * mars 2014 * * mars 2014 * *************
does has solution this? time!
your foreach should done after loop done.
the last loop 3 example .. options same $i
. overwriting $options
3 times in code.
for ($i = 0; $i < count($moisstring); $i++) { $month[] = $moisstring[$i]; $annee[]= $year[$i]; } $counter = 0; foreach ($fichefrais $mois) { $options[$mois->mois] = $month[$counter]." ".$annee[$counter++]; }
Comments
Post a Comment