php - Warning: Invalid argument supplied for foreach() but $data is an array -


i working form , encountered problem. don't understand, why "invalid argument supplied foreach()" occurs because $data array. think bad in foreach loop. it's code:

        $data  = array(           'cityc'   => $_post['cityc'],           'month'   => $_post['month'],           'year'    => $_post['year']         );         echo 'in ' . $data['cityc'] . ' in month of ' . $data['month'] .         ' ' . $data['year'] . ', observed following weather:<br /><ul>';         $weatherx = $_post['weather'];         foreach ($weatherx $key => $valuex) {           foreach ($weatherx $value) {             echo '<li>' . $value . '</li>';           }         }         echo '</ul>';         echo           '<form action="" method="post">            <p>Įvertinkite mėnesio orą </p>            miestas: <input type="text" name="cityc" autocomplete="off"><br /><br             />            mėnesis: <input type="text" name="month" autocomplete="off"><br /><br             />            metai: <input type="text" name="year" autocomplete="off"><br /><br             />';                foreach ($weather $value) {              echo '<input type="checkbox" name="' . $value . '" value="' .               $value . '"> '. ucfirst($value) . '<br />';            }            echo '<br /><input type="submit" value="tęsti">         </form>'; } 

here image how looks when submit form filled in fields (s, s, s, rain)

i don't know how fix error, trying use multidimensional array:

              $data  = array(                 'cityc'   => $_post['cityc'],                 'month'   => $_post['month'],                 'year'    => $_post['year'],                 'weather' => array(                   'rain'     => @$_post['rain'],                   'sunshine' => @$_post['sunshine'],                   'clouds'   => @$_post['clouds'],                   'hail'     => @$_post['hail'],                   'sleet'    => @$_post['sleet'],                   'snow'     => @$_post['snow'],                   'wind'     => @$_post['wind']                 )               );               echo 'in ' . $data['cityc'] . ' in month of ' . $data['month'] . ' ' . $data['year'] . ', observed following weather:<br /><ul>';               foreach ($data $key => $valuex) {                 foreach ($valuex $value) {                   echo '<li>' . ucfirst($value) . '</li>';                 }               }               echo '</ul>';         echo @$cityerror;  } 

here image how looks when submit form filled in fields (s, s, s, rain)

still getting error , don't know how fix it. haven't seen before.

p.s sorry indentation, using 2 tabs.

try

    foreach($data['weather'] $weather){         $weather['rain']; #etc      } 

edit data don't need forech. can value variable $data['weather']['rain'], etc.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -