Parse Error Syntax Error Unexpected T_function Array_filter
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 t_function error php this site About Us Learn more about Stack Overflow the company Business Learn unexpected t_function wordpress more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question
T_function Php
x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up
Syntax Error Unexpected T_function Usort
Parse error: syntax error, unexpected T_FUNCTION [duplicate] up vote -2 down vote favorite Possible Duplicate: Parse error: syntax error, unexpected T_FUNCTION line 10 ? help? Reference - What does this error mean in PHP? This is the code which cause the error. $remaining = array_filter($allmodels, function ($var) use ($existmodels) { return !in_array($var, $existmodels); }); Logic of the code is(below all are arrays) $remaining = unexpected function c++ $allmodels - $existmodels; I think My PHP version is outdated in the server. Is it the problem. How can I create a similar code snippet ? Thanks php share|improve this question edited Oct 25 '12 at 8:47 hakre 134k26216390 asked Oct 25 '12 at 8:15 Techie 22.3k2089172 marked as duplicate by Gordon, Christian, DaveRandom, hakre, j0k Oct 25 '12 at 9:02 This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. (reference) php.net/callbacks –Gordon Oct 25 '12 at 8:22 What's your hosting service PHP version? If it's too outdated, you may consider migrating. Starting a new project on 5.2 or older is not worth the effort. –Álvaro González Oct 25 '12 at 8:22 Thanks for the support people –Techie Oct 25 '12 at 8:32 add a comment| 3 Answers 3 active oldest votes up vote 2 down vote accepted I am a big fan of OO programming, so just for the fun: class MyArrayOperations { private $base; public function __construct(array $base) { $this->base = $base; } pu
'value 2', 'bleh', 'dont remove me'); $drop = php function array('value 1', 'bleh'); Now I want to filter // drop elements from $drop out of $array I tried this (which seems to be the most elegant way to do it): $filtered_array = array_filter($array, http://stackoverflow.com/questions/13064376/parse-error-syntax-error-unexpected-t-function function($element) { return (!in_array($element, $drop)); } ); But I get: Parse error: syntax error, unexpected T_FUNCTION in /Applications/MAMP/htdocs/ ... I even get the same error if I try to call this (I use PHP 5): $test = array_filter($drop, function($a) { return https://www.sitepoint.com/community/t/php-filtering-array-problem/83059 !is_null($a) }); What is going on? Thanks for help StarLion 2011-04-28 15:05:43 UTC #2 What you are describing is already a defined function. array_diff l2u 2011-04-28 15:33:37 UTC #3 Thanks.. but why doesn't the code above work? StarLion 2011-04-28 15:42:19 UTC #4 $filtered_array = array_filter($array, function($element) { return (!in_array($element, $drop)); } );worked fine for me (other than throwing errors for $array and $element not being defined). No idea why yours is throwing a syntax error. aamonkey 2011-04-28 17:30:43 UTC #5 l2u said: Thanks.. but why doesn't the code above work? You need php 5.3 or higher to use anonymous functions Home Categories FAQ/Guidelines Terms of Service Privacy Policy Powered by Discourse, best viewed with JavaScript enabled Shop Versioning Reference Articles Premium
Sign in Pricing Blog Support Search GitHub This repository Watch 63 Star 91 Fork 21 box/RainGauge Code Issues 15 Pull requests 3 Projects https://github.com/box/RainGauge/issues/3 0 Wiki Pulse Graphs New issue Parse error: syntax error, unexpected T_FUNCTION in RainGauge/lib/RainGauge.php on line 77 #3 Closed djuntgen opened this Issue Aug 8, 2012 · 2 comments https://www.reddit.com/r/drupal/comments/4ydtqn/php_parse_error_syntax_error_unexpected_t/ Projects None yet Labels bug Milestone No milestone Assignees No one assigned 2 participants djuntgen commented Aug 8, 2012 Parse error: syntax error, unexpected T_FUNCTION in syntax error RainGauge/lib/RainGauge.php on line 77 My version of PHP: PHP 5.2.17 (cli) (built: Jul 9 2011 19:39:29) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies Problem: Anonymous functions became available in 5.3 gtowey commented Aug 8, 2012 There are quite a few instances of anonymous functions, I would have to convert them all. Let syntax error unexpected me think about this one. lib/RainGaugeModel.php: usort($samples, function ($a, $b) use ($sort_key) { lib/RainGaugeModel.php: usort($series, function ($a, $b) { lib/RainGauge.php: usort($data['samples'], function ($a, $b) use ($sort_key) { lib/RainGauge.php: $result = array_filter($result, function ($x) { lib/RainGauge.php: $data['flot_data'][] = array('label' => $var_name, 'data' => array_map(function ($i, $x) { lib/RainGauge.php: function ($i, $x, $y) { lib/RainGauge.php: usort($samples, function ($a, $b) use ($sort_key) { lib/RainGauge.php: usort($samples, function ($a, $b) use ($sort_key) { lib/RainGauge.php: usort($data['samples'], function ($a, $b) use ($sort_key) { djuntgen commented Aug 9, 2012 Gavin - PHP 5.2 is old, I was able to get my system upgraded to the stable PHP 5.3 version. This resolved those issues. … On Wed, Aug 8, 2012 at 4:29 PM, Gavin Towey ***@***.***>wrote: There are quite a few instances of anonymous functions, I would have to convert them all. Let me think about this one. lib/RainGaugeModel.php: usort($samples, function ($a, $b) use ($sort_key) { lib/RainGaugeModel.php: usort($series, function ($a, $b) { lib/RainGauge.php: usort($data['samples'], function ($a, $b) use ($sort_key) { lib/RainGauge.php: $result = array_filter($result, function ($x) { lib/RainGauge.php: $data['flot_data'][] = array('label' => $var_name,
»reddit.comdrupalcommentsWant to join? Log in or sign up in seconds.|Englishlimit my search to /r/drupaluse the following search parameters to narrow your results:subreddit:subredditfind submissions in "subreddit"author:usernamefind submissions by "username"site:example.comfind submissions from "example.com"url:textsearch for "text" in urlselftext:textsearch for "text" in self post contentsself:yes (or self:no)include (or exclude) self postsnsfw:yes (or nsfw:no)include (or exclude) results marked as NSFWe.g. subreddit:aww site:imgur.com dogsee the search faq for details.advanced search: by author, subreddit...this post was submitted on 18 Aug 20161 point (100% upvoted)shortlink: remember mereset passwordloginSubmit a new linkSubmit A New Postdrupalsubscribeunsubscribe6,501 readers~5 users here nowCheck out the sidebar for our AMA schedule, or view our past A