Solved

The name of variable vs real number

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

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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.

685 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