Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

The name of variable vs real number

Posted on 2009-06-27
1
Medium Priority
?
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

721 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