Solved

The name of variable vs real number

Posted on 2009-06-27
1
211 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
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.  …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

929 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

11 Experts available now in Live!

Get 1:1 Help Now