Php Foreach Syntax Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the syntax error, unexpected 'foreach' (t_foreach) laravel company Business Learn more about hiring developers or posting ads with us Stack Overflow
Syntax Error, Unexpected 'foreach' (t_foreach) In Laravel 5
Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 syntax error unexpected foreach t_foreach in php million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up getting PHP syntax error unexpected 'foreach' (T_FOREACH) up vote 1 down vote favorite I am trying to make a unexpected php foreach code that automatically makes my header for my site. The idea is that as I add more pages I can just add them to the array and it will auto update the header for me. Usually my foreach'es work but for the first time I am having trouble. I tried it two ways, both of which spat out the same error.
Parse Error Syntax Error Unexpected
= array("Home", "About") foreach($names as $name){ echo " $name "; } ?> $name "; } } ?> php foreach header share|improve this question edited Dec 3 '14 at 2:18 John Conde 156k70289364 asked Dec 3 '14 at 2:17 Andre Ellis 2813 1 As always, you're missing a semi-colon. –John Conde Dec 3 '14 at 2:18 ... $names = array("Home", "About") <= John means there. –Fred -ii- Dec 3 '14 at 2:18 @JohnConde See, our comments are worth the paper they were written on. Comments ignored. –Fred -ii- Dec 3 '14 at 2:22 @Fred-ii- at least no trees where harmed. –John Conde Dec 3 '14 at 2:39 @JohnConde Thank the good Lord for that. –Fred -ii- Dec 3 '14 at 2:40 | show 1 more comment 3 Answers 3 active oldest votes up vote 1 down vote Usually when PHP returns "unexpected" it means the thing before it is not quite right, as with this case: You have $names = array("Home", "About") <-- no semi colon to end the line, and so the next line foreach is unexpected, as it was "expecting" a ; And
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the foreach php workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join http://stackoverflow.com/questions/27262558/getting-php-syntax-error-unexpected-foreach-t-foreach them; it only takes a minute: Sign up Parse error: syntax error, unexpected 'foreach' (T_FOREACH) [closed] up vote -5 down vote favorite How can i fix this? i want make this : $diagnosa=blabla , blabla2 , blabla3 , ; and then i use foreach but it cannot work, $nama_diagnosa = Laporan::ViewDataDiagnosa(2,'2015-02-02'); $diagnosa = foreach ($nama_diagnosa as $cellDiagnosa){ echo $cellDiagnosa['nama_diagnosa']." http://stackoverflow.com/questions/28182311/parse-error-syntax-error-unexpected-foreach-t-foreach , "; } php arrays string share|improve this question edited Jan 28 '15 at 0:10 potashin 30.5k44274 asked Jan 28 '15 at 0:00 reegha 12 closed as unclear what you're asking by Rizier123, halfer, Infinite Recursion, winterblood, andrewsi Jan 28 '15 at 3:00 Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question. 2 Use array_column and implode. –mario Jan 28 '15 at 0:03 so, how can i fix it? –reegha Jan 28 '15 at 0:04 Is the first line meant to be an array? At the moment this would just produce a syntax error. –halfer Jan 28 '15 at 0:21 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote accepted [resolved] Finally I added temporary variables to hold data f
and Objects Namespaces Errors Exceptions Generators References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Context options and parameters Supported Protocols and Wrappers Security Introduction General considerations Installed as http://php.net/manual/en/control-structures.alternative-syntax.php CGI binary Installed as an Apache module Session Security Filesystem Security Database Security Error Reporting Using Register Globals User Submitted Data Magic Quotes Hiding PHP Keeping Current Features HTTP https://www.drupal.org/node/2793077 authentication with PHP Cookies Sessions Dealing with XForms Handling file uploads Using remote files Connection handling Persistent Database Connections Safe Mode Command line usage Garbage Collection DTrace Dynamic Tracing syntax error Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Credit Card Processing Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other syntax error, unexpected Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation GUI Extensions Keyboard Shortcuts? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto search(current page) / Focus search box while » « elseif/else if PHP Manual Language Reference Control Structures Change language: English Brazilian Portuguese Chinese (Simplified) French German Japanese Korean Romanian Russian Spanish Turkish Other Edit Report a Bug Alternative syntax for control structures (PHP 4, PHP 5, PHP 7) PHP offers an alternative syntax for some of its control structures; namely, if, while, for, foreach, and switch. In each case, the basic form of the alternate syntax is to change the opening brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively. if($a==