fundamental PHP foreach question!

Weird!  Hopefully this is an easy 1000 points for someone.

This is taken straight from the manual, and I get an error - anyone see it?  I'm using CodeIgniter if that's relevant at all.

syntax error, unexpected '$v' (T_VARIABLE) in C:\xampp\htdocs1\fobg\application\controllers\week_fixtures.php on line 31

public function date_chosen()
            $a = array(1, 2, 3, 17);

            foreach ($a as $v) {
                echo "Current value of \$a: $v.\n";

also flagged up in Dreamweaver:
DW screenshot
Colin BrazierAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Works for me

Try changing $v to something else
Try putting $v.\n in string in { }
echo "Current value of \$a: {$v}.\n";

Try deleting and retyping line 31.
Colin BrazierAuthor Commented:
Hi Julian, this is what I get with
public function date_chosen()
		$a = array(1, 2, 3, 17);		

Open in new window

Call to undefined function  array() in C:\xampp\htdocs1\fobg\application\controllers\week_fixtures.php on line 29
Colin BrazierAuthor Commented:
I restarted Apache and DW no longer flags an error, but despite delete cache and hard reload the error persists.

In Chrome and Edge.

I need to go out for a couple of hours. Will reboot when I get back.

HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Colin BrazierAuthor Commented:
Absolutely bizarre.
Chris StanyonWebDevCommented:
There's fundamentally nothing wrong with the code you've posted in isolation. I've just pasted it straight into a CodeIgniter controller and it worked as it should.

Sometimes errors point to line numbers that just don't make sense, so I would take a look at the controller code as a whole. Remove parts if necessary to double-check that the error isn't actually being caused by code further up the file ... it happens sometimes !!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Colin BrazierAuthor Commented:
Thanks Chris, I'm new to CI so that must be the underlying reason.  I'll go back and revisit it.

Colin BrazierAuthor Commented:
Well I stripped it and it seems OK now.  What a waste of a morning.

Thanks both.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.