Solved

The name of variable vs real number

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
can i read my emails on lamp ftp 4 71
PHP Web Development 6 71
How do I Import CSV File In my PHP Application 29 76
SSL unsecure page mystery 17 47
This article discusses how to create an extensible mechanism for linked drop downs.
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…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

752 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