jeudi 29 avril 2010

Quick trick

Want to know easily if a given array is multi-dimensional ?
<?php
if (count($array) != count($array, COUNT_RECURSIVE)) {
  echo "this is a multidimensional array";
}
?>
There you go.
Note that there's a caveat: if the second dimension element is an empty array, this will yield FALSE:
<?php
$array = array(
  1,
  2,
  3,
  array(),
  4
);
?>
will NOT say this is a multidimensional array.