Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,205,858 members, 7,993,956 topics. Date: Monday, 04 November 2024 at 11:05 PM

PHP Simple Puzzle - Webmasters (3) - Nairaland

Nairaland Forum / Science/Technology / Webmasters / PHP Simple Puzzle (3835 Views)

Web Masters Please Help Me Solve This Puzzle / I Challenge The Level Of Intelligence On This Forum With This Puzzle. (2) (3) (4)

(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)

Fresh Google Voice Numbers For Sale Daily / Pop Up Window Script That Is Multi Browser Supported? / Problem: Centering Text Using Php's Imagettftext

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 9
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.