[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($willFilte rByLetter, $letter) =
array($_REQUEST['willFilterByLe tter'], $_REQUEST['letter']);
if ($willFilterByL etter && preg_match('/[a-z]/i', $letter)) {
$filterAt = $this->filterAtArra y[$section];
array_walk($res ult, 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 1 1812
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($willFilte rByLetter, $letter) =
array($_REQUEST['willFilterByLe tter'], $_REQUEST['letter']);
if (is_array($resu lt) && @sizeof($result ) > 0 && $willFilterByLe tter
&& strlen($letter) == 1 && ctype_alpha($le tter)) {
$filterAt = $this->getFilterAtArr ay($section); // ONLY RETRIEVE
THE VALUE OF $this->filterAtArra y[$section]
$filteredResult = array();
for ($i = 0; $i < @sizeof($result ); $i++)
if (strpos(strtolo wer($result[$i]->$filterAt), strtolower($let ter))
=== 0) array_push($fil teredResult, $result[$i]);
@reset($filtere dResult);
}
return $filteredResult ;
}
Phil This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Phil Powell |
last post by:
<?php
class Grad {
var $dbFormExemptionArray = array();
function Grad ($id = '') {
/*----------------------------------------------------------------------------------------------------------------------
Do note that if you are generating arrays that will not have
|
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 solve my problem - But I've not got
the foggiest
on how to use it - I've taken a look in the php.chm manual supplied from
php.net and I don't seem...
|
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 want to use the array with an ID
Something like,
|
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 you pass a Value-Type to method call
,Boxing and Unboxing would happen,Consider the following snippet:
int a=1355;
myMethod(a);
......
|
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 has a method ProcessRequest()
| |
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 the html page
controls the form fields that are required. It doesn't function like
it's supposed to and I can leave all the fields blank and it still...
|
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 <string>
|
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 a function
|
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
directory to my local hard drive, but the tasks keep failing after a large
file is downloaded. The error I'm getting is:
An error occurred in the...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |