php - Check if array empty -


this question has answer here:

problem: unwanted empty post(s) saved when saving multiple posts.

question: how check if array empty?

i want check if $value[0] empty , save values containing text.

please feel free change code below or use new example.

foreach ($_post['bedomning'] $elevens_id => $value) {      $ident = $_post['ident'];        $amne_id = $_post['amne_id'];        $datumet = $_post['datum'];              $lararen = $_session['lid'];      $array_empty = array_filter($value[0]);      if (!empty($array_empty)){             try{                  $ny_bedomning  = $db->prepare("                              insert `abb_larare`                  (ident, amne_id, abb_bed_text, elev_id, lid, datum)                  values (:ident, :amne_id, :abb_bed_text, :elev_id, :lid, :datum)              ");                                       $ny_bedomning->bindparam(':ident', $ident, pdo::param_str);             $ny_bedomning->bindparam(':amne_id', $amne_id, pdo::param_int);             $ny_bedomning->bindparam(':abb_bed_text', $value[0], pdo::param_str);             $ny_bedomning->bindparam(':elev_id', $elevens_id, pdo::param_int);               $ny_bedomning->bindparam(':lid', $lararen, pdo::param_int);              $ny_bedomning->bindparam(':datum', $datumet, pdo::param_str);                     $ny_bedomning->execute();             }catch(pdoexception $e){         die($e->getmessage());         }     } } 

use empty() check empty value. try -

if (!empty($value[0])) {    // staff } 

empty works -

  • "" (an empty string)
  • 0 (0 integer)
  • 0.0 (0 float)
  • "0" (0 string)
  • null
  • false
  • array() (an empty array)
  • $var; (a variable declared, without value)

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -