0

I using this code

$dato = array_shift($datos);
while($dato!=''){...}

Is it correct?

Is the same to put:

while($dato!=''){...}

Than

while($dato!=null){...}

Edit: This is on the oficial documentation php

Returns the shifted value, or NULL if array is empty or is not an array.

But my code is actually running

KaSkuLL
  • 531
  • 6
  • 27
  • 2
    Did you try it? What is null and what is empty when you read the manual? – Andreas Dec 02 '18 at 13:14
  • Possible duplicate of [What is the difference between null and empty?](https://stackoverflow.com/questions/5615747/what-is-the-difference-between-null-and-empty) – A l w a y s S u n n y Dec 02 '18 at 13:15
  • https://stackoverflow.com/questions/41887897/how-do-i-validate-null-or-empty-in-php – jvk Dec 02 '18 at 13:15
  • @Andreas yes i've tried, i'm studing engineering and my teacher said that my code was not ok. But is actually runnig. By the way also he told me there are no booleans on php??? That is not true lol – KaSkuLL Dec 02 '18 at 13:16
  • Null = no value, '' = empty string. Also you can try it $var = ''; if($var == null){ echo 'var is null'; } else { echo 'var is not null';} – bakero98 Dec 02 '18 at 13:16

3 Answers3

0

I think you are trying to check the value is empty in any array

while(!empty($dato)){...}
jvk
  • 2,133
  • 3
  • 19
  • 28
0

NULL = Doesn't exist
'' = Exists but it's empty

Universe
  • 1
  • 1
0

You can validate in many ways :

  1. By using php variable handling function is_null(mixed $var)
  2. By using php variable handling function is set(mixed $var)
  3. By using php variable handling function empty(mixed $var)
  4. By using comparison operator ==, === or !=