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
LVL 3
colinspursAsked:
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.
0
colinspursAuthor 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
0
colinspursAuthor 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.

Cheers
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

colinspursAuthor Commented:
Absolutely bizarre.
0
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 !!
0

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
colinspursAuthor Commented:
Thanks Chris, I'm new to CI so that must be the underlying reason.  I'll go back and revisit it.

Cheers
0
colinspursAuthor Commented:
Well I stripped it and it seems OK now.  What a waste of a morning.

Thanks both.
0
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
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.