473,387 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Can't obtain value of $filterAt within array_walk() function within method

[PHP]
/**
* Filter results according to given instruction
*
* @access private
* @param object $result (reference)
* @return object $filteredResult
*/
function &filterResults(&$result) { // STATIC OBJECT ARRAY
METHOD
global $section;
list($willFilterByLetter, $letter) =
array($_REQUEST['willFilterByLetter'], $_REQUEST['letter']);
if ($willFilterByLetter && preg_match('/[a-z]/i', $letter)) {
$filterAt = $this->filterAtArray[$section];
array_walk($result, create_function('&$a', 'global $filterAt,
$letter; if (!preg_match("/^$letter/i", $a->$filterAt)) unset($a);'));
}
return $result;
}
[/PHP]

I can't obtain $filterAt within the create_function()-created function
within array_walk(), yet I can obtain $letter. I verified this via
using print_r to show that $letter exists while $filterAt does not,
however, $filterAt DOES exist prior to array_walk().

Could someone tell me what I did wrong?

Thanx
Phil

Jul 17 '05 #1
1 1800
I found it, but I absolutely don't like it. You apparently cannot use
unset() within array_walk(), which I personally think is inefficient
since other languages, including Java, do this very same thing.

I had to do a primitive brute-force method:

/**
* Filter results according to given instruction
*
* @access private
* @param object $result (optional)
* @return object $filteredResult
*/
function &filterResults($result = '') { // STATIC OBJECT
ARRAY METHOD
global $section;
list($willFilterByLetter, $letter) =
array($_REQUEST['willFilterByLetter'], $_REQUEST['letter']);
if (is_array($result) && @sizeof($result) > 0 && $willFilterByLetter
&& strlen($letter) == 1 && ctype_alpha($letter)) {
$filterAt = $this->getFilterAtArray($section); // ONLY RETRIEVE
THE VALUE OF $this->filterAtArray[$section]
$filteredResult = array();
for ($i = 0; $i < @sizeof($result); $i++)
if (strpos(strtolower($result[$i]->$filterAt), strtolower($letter))
=== 0) array_push($filteredResult, $result[$i]);
@reset($filteredResult);
}
return $filteredResult;
}

Phil

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phil Powell | last post by:
<?php class Grad { var $dbFormExemptionArray = array(); function Grad ($id = '') { ...
2
by: Reply-Via-Newsgroup | last post by:
Folks, I have a multi-dimensional array that I read from my mysql database. I'd like to run strip slashes against each element and I'm pretty sure that array_walk() (or array_map) is likely to...
6
by: Sims | last post by:
Hi, Given a string $txt and an array of strings $txt_array what would be the best/fastest way to search in _insensitive_ case if $txt is in $text_array and, if it is, where is it? Because I...
24
by: ALI-R | last post by:
Hi All, First of all I think this is gonna be one of those threads :-) since I have bunch of questions which make this very controversial:-0) Ok,Let's see: I was reading an article that When...
5
by: OneFang | last post by:
Hi I hope I make sense here. I want to be able to obtain the name of the method that calls a method within my class. So If I have my class that has a method LogInfo() And my client code...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
2
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
7
by: =?Utf-8?B?SmFzb24=?= | last post by:
Hello, can someone please suggest to me how I can keep my ftp connection from timing out after a large file download? I am using SSIS and I have tried multiple ways of ftp'ing the files in my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.