Solved

The name of variable vs real number

Posted on 2009-06-27
1
210 Views
Last Modified: 2012-05-07
Hi E's, I have a line of code that work with a real number, but don't word with the name of variable.
The line is this one, and in this way work well:
====================================
$keysrel_numeracao = array_filter(array_values($keysrel_numeracao),create_function('$item','return $item>=11;'));
====================================

The problem is, I want substitute the real number (11) to a name of variable ($number), and the script don't work, like:
====================================
$number = 11;
$keysrel_numeracao = array_filter(array_values($keysrel_numeracao),create_function('$item','return $item>=$number;'));
====================================
The script don't work, and don't give me any error.

My question is, what is the correct way to change the number 11 to the variable $number?

Regards, JC


0
Comment
Question by:Pedro Chagas
1 Comment
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 125 total points
ID: 24729820
You have two options: either define the variable as a global within the function, or resolve the variable before the function is created:
# define as global

$number = 11;

$keysrel_numeracao = array_filter(array_values($keysrel_numeracao),

  create_function('$item','global $number; return $item>=$number;'));
 

# variable resolved before function is created 

$number = 11;

$keysrel_numeracao = array_filter(array_values($keysrel_numeracao),

  create_function('$item','return $item>='.$number.';'));

Open in new window

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now