update page now

Voting

: three plus six?
(Example: nine)

The Note You're Voting On

Sbastien
3 years ago
Because of PHP comparaisons modalities, you can never distinguish null from others falsy values.
Note the absorbing nature of true and false booleans in mix types array.

<?php

$a = [true, false, null, '', '0', '123', 0, 123];
foreach (['SORT_REGULAR', 'SORT_NUMERIC', 'SORT_STRING', 'SORT_LOCALE_STRING'] as $flag) {
    $a_new = array_unique($a, constant($flag));
    echo "{$flag} ==> ";
    var_dump($a_new);
}

/*

Gives :

SORT_REGULAR ==> array(2) {
  [0]=> bool(true)
  [1]=> bool(false)
}
SORT_NUMERIC ==> array(3) {
  [0]=> bool(true)
  [1]=> bool(false)
  [5]=> string(3) "123"
}
SORT_STRING ==> array(4) {
  [0]=> bool(true)
  [1]=> bool(false)
  [4]=> string(1) "0"
  [5]=> string(3) "123"
}
SORT_LOCALE_STRING ==> array(4) {
  [0]=> bool(true)
  [1]=> bool(false)
  [4]=> string(1) "0"
  [5]=> string(3) "123"
}

*/

<< Back to user notes page

To Top