Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Gurinder121's avatar

Help with PHP code

Hi guys,

I'm new to programming. If I need to put down more info, please let me know a command

Warning: Invalid argument supplied for foreach() in /Users/gurinderkhabra/Desktop/php-learning/index.view.php on line 10

Here is the command

Document
<ul>
	<?php foreach ($tasks as $task) : ?>   <! -- this is line 10 -->
		<li>
			<?php if ($task->completed) : ?>
				<strike><?= $task->description; ?></strike>
			<?php endif; ?>
		</li>
	<?php endforeach; ?>
	</ul>

</body>
</html>
0 likes
6 replies
bobbybouwmann's avatar

Well, you do a foreach on the $tasks variable. However, if $tasks is not an array this won't work.

Can you show us the code where you assign the value to $tasks?

jlrdw's avatar

Is that code from one of the video lessons? If so I'm pretty sure that code is also available on GitHub.

jlrdw's avatar

Usually if there's a lesson on GitHub he has a link right in the description of the video.

jlrdw's avatar

Look at the text below the very last episode there is a GitHub link there.

Please or to participate in this conversation.