How To Use Iterables Function in PHP Example
Hi guys,
Today i will explained What is an Iterable In PHP. This example is so easy to use in php.
An iterable is any value which can be looped through with a foreach() loop. The iterable pseudo-type was introduced in PHP 7.1, and it can be used as a data type for function arguments and function return values.
So let's start to the example.
Iterable
The iterable keyword can be used as a data type of a function argument or as the return type of a function.
<!DOCTYPE html>
<html>
<body>
<?php
function printIterable(iterable $myIterable) {
foreach($myIterable as $item) {
echo $item;
}
}
$arr = ["a", "b", "c"];
printIterable($arr);
?>
</body>
</html>
Output
abc
Now you can check your own.
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example