₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,161 members, 8,420,616 topics. Date: Friday, 05 June 2026 at 07:10 AM

Toggle theme

PHP Simple Puzzle - Webmasters (3) - Nairaland

Nairaland ForumScience/TechnologyWebmastersPHP Simple Puzzle (4093 Views)

1 2 3 Reply

Re: PHP Simple Puzzle by romme2u: 12:45am On Jul 18, 2013
Web Contractor: I must say,you attacked it nicely.Just a little explanation for learners to follow.

Foreach loops can only be used with arrays.
it has the format

<?php
foreach($array as $value){
statement;
}
?>

Foreach loop will go through every single element of the array($array) and each of the elements(2,4,6,8,10,12) will become the value($value) which can then be referenced in the statement.

Simply put,we are pulling each of the elements in the array and assigning them to a variable name temporarily, and then executing a statement on them.
that bolded section should be
foreach($key=>$value){execute statement here}
since arrays consists of keys and values.
1 2 3 Reply

Web Masters Please Help Me Solve This PuzzleI Challenge The Level Of Intelligence On This Forum With This Puzzle.234

What's Your Best Content Marketing Tip?SOLVE All Your WORDPRESS Related PROBLEMS!!!Basic Tips To Protect Your Website From Hackers