1

i want to do the foreach only if the content of myformdata[languages1][] is not empty (include zero)

I already try:

  foreach((!empty($form['languages1']) as $val){

and

if (!empty($form['languages1'][])) {
foreach($form['languages1'] as $val){
//do stuff
}

i don't have any success. At the moment with the code below the loop is made when the input of myformdata[languages1][] is 0

foreach

foreach($form['languages1'] as $val){
//do stuff
}

thanks

1
  • The first foreach doesn't even make sense. You're saying BOOLEAN as $value? Commented Jun 23, 2011 at 21:38

2 Answers 2

2
foreach ( $form['languages1'] as $val )
{
  // If the value is empty, skip to the next.
  if ( empty($val) )
    continue;
}

Reference: http://ca.php.net/continue

Sign up to request clarification or add additional context in comments.

1 Comment

Alternatively if(!empty($val)){ //do stuff }. Continue belongs here though.
1

You're dealing with type coersion

You probably want something like

if(!empty($form['languages1']) && $form['languages1'] !== 0)

So that PHP will match 0 as a number, and not as false.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.