-1

I won't display string if value of $post['time'] === null or $post['time'] === ''. Look my response https://i.stack.imgur.com/pgFMC.jpg , I won't to show this string 'Um' and 'Uhr' if input type for date not selected(if $post['time'] === null or ''). Look my code. Main of code is this foreach loop. var_dump($message I using only for testing.

$message = '';
        $termini = '<p>Terminvorschlagen:</p>';

        foreach ($post['date'] as $i => $date) { 

            if($post['date'] !== NULL || $post['date'] !== '' || $post['time'] !== NULL || $post['time'] !== '') {
                $termini .= '<p>' . $i + 1 . '. ' . $date . 'um, ' . $post['time'][$i] . 'Uhr</p>';
            }
        }


        $message .= 'Name: ' . $post['name'] . '<br />';
        $message .= 'Phone: ' . $post['phone'] . '<br />';
        $message .= 'Email: ' . $post['email'] . '<br />';

        $message .= '<br />';

        $message .= 'Pneu-Typ: ' . $post['pneu'] . '<br />';
        $message .= 'Anzahl Pneus zur Montage: ' . $post['anzahl'] . '<br />';
        $message .= 'Marka: ' . $marka . '<br />';
        $message .= 'Model: ' . $model . '<br />';

        $message .= '<br />';

        $message .= $termini;
        var_dump($message);
        return;
Alex Al
  • 156
  • 4
  • 17
  • I honestly have no idea what you're trying to say, but I'll tell you this; `$post['date'] !== NULL || $post['date'] !== ''` will _always_ be true, because something that _is_ exactly one thing, is by definition _not_ exactly another thing. So if a value _is_ `null`, then it is _not_ an empty string (and vice versa). – Patrick Q Feb 22 '19 at 13:53

1 Answers1

1

use && instead of || if you want to check both the condition...

PHP empty() functions check if the value is (0,"",null)

  if(empty($post['date']) || empty($post['time'])) {

 $termini .= '<p>' . $i + 1 . '. ' . $date . 'um, ' . $post['time'][$i] . 'Uhr</p>';

    }
Sayed Mohd Ali
  • 2,156
  • 3
  • 12
  • 28
  • use && instead of || if you don't want both date and time not to be empty. for the above code... – Sayed Mohd Ali Feb 22 '19 at 14:06
  • Okey I use this but about I got 'um' and 'Uhr' look my code foreach ($post['date'] as $i => $date) { if(!empty($post['date']) && !empty($post['time'])) { $termini .= '

    ' . $i + 1 . '. ' . $date . 'um, ' . $post['time'][$i] . 'Uhr

    '; } }
    – Alex Al Feb 22 '19 at 14:07
  • I try but again I got same result...Again is here 'um' and 'Uhr' . If I can say if variable empty not show anythink... – Alex Al Feb 22 '19 at 14:11
  • print_R(post);die; before using it inside foreach loop and check [date] and [time] is empty or not... it must not be empty that is why you are getting result umm and urh – Sayed Mohd Ali Feb 22 '19 at 14:15
  • you can use die("error""); inside if(condition) to check it is working or not... – Sayed Mohd Ali Feb 22 '19 at 14:15
  • I do it. My code at in if block...but my logic is bad...I need foreach if any input type empty not show 'um' and 'Uhr' only show empty string, if $post['time'] or date here show me.... Little confused – Alex Al Feb 22 '19 at 14:23
  • There is enough only one field is filled and conditional is true....because my code is always true...only one input of three maybe filled and conditional is true... – Alex Al Feb 22 '19 at 14:27
  • just do one thing edit you question... first and clearify you problem with example print_r($post) array and show it first then the result you wanted... example of it... as you cannot clearify you question it will end up in blind guesses... – Sayed Mohd Ali Feb 22 '19 at 14:29
  • currently according to the logic if any of the value of $post array index date and time is not empty it will end up in UMM and URH... but now you are saying your logic is different so you have to explain the logic you wanting with example... – Sayed Mohd Ali Feb 22 '19 at 14:31
  • Okey this is my $post Array ( [pneu] => Moto[marka] => APRILIA [model] => RS4 50 [anzah4] => 1 [date] => Array ( [0] => 01/03/2019 [1] => [2] => ) [time] => Array ( [0] => 10:30 [1] => [2] => ) [accept] => on [name] => Test Test [phone] => 12345678901[email] => test@gmail.com ) – Alex Al Feb 22 '19 at 14:33
  • according to this array date and time is not empty for each values of date and time that is why you are getting umm and urh as output... – Sayed Mohd Ali Feb 22 '19 at 14:35
  • Yes but I have Array with [0] which is filled and [1] and [2] which is empty.... I want not show 'um' and 'uhr' if any index empty...that is logic – Alex Al Feb 22 '19 at 14:38
  • @AlexAl okay alex I got it use the code i have updated now for you – Sayed Mohd Ali Feb 23 '19 at 19:27