Level 47
Use foreach.
$arr = array('hello', 'my', 'world');
foreach ($arr as $item) {
echo $item;
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am learning PHP and Laravel together. And I have got one array which I am printing in PHP . This is what I have tried. Can I improve or optimize this below code.
$arr = array('hello', 'my', 'world');
$i = 0;
while($i < count($arr))
{
echo $arr[$i];
$i++;
}
Use foreach.
$arr = array('hello', 'my', 'world');
foreach ($arr as $item) {
echo $item;
}
Please or to participate in this conversation.