PHP iterable to array or Traversable : <p>I'm quite happy that PHP 7.1 introduced <a href="https://secure.php.net/manual/en/language.types.iterable.php" rel="noreferrer">the iterable pseudo-type</a>.</p>

<p>Now while this is great when just looping over a parameter of this type, it is unclear to me what to do when you need to pass it to PHP functions that accept just an <code>array</code> or just a <code>Traversable</code>. For instance, if you want to do an array_diff, and your <code>iterable</code> is a <code>Traversable</code>, you will get an <code>array</code>. Conversely, if you call a function that takes an Iterator, you will get an error if the <code>iterable</code> is an <code>array</code>.</p>

<p>Is there something like <code>iterable_to_array</code> (NOT: <code>iterator_to_array</code>) and <code>iterable_to_traversable</code>?</p>

<p>I'm looking for a solution that avoids conditionals in my functions just to take care of this difference, and that does not depend on me defining my own global functions.</p>

<p>Using PHP 7.1</p>
