473,327 Members | 2,118 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,327 software developers and data experts.

Can someone help me with array_walk/array_map?


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 to have had any success so far - Can anyone suggest
how I could stripslashes to every element without having to build my own
function?

(I don't want to use my own function when one already exists in PHP - In
part, because its more performance effective to use a precompiled function).

all helps.. via the newsgroup... is much apprecaited,

thanks
randelld

Jul 17 '05 #1
2 2922
Reply-Via-Newsgroup wrote:
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 to have had any success so far - Can anyone suggest
how I could stripslashes to every element without having to build my own
function?

(I don't want to use my own function when one already exists in PHP - In
part, because its more performance effective to use a precompiled function).

all helps.. via the newsgroup... is much apprecaited,

thanks
randelld


Try the following (untested) function:

function stripSlashes(&$var) {
if (is_string($var)) {
$var = stripslashes($var);
} else { // assume it is an array
foreach($var as $key => $value) {
stripSlashes($var[$key]);
}
}
}

--
Amir Khawaja.

----------------------------------
Rules are written for those who lack the ability to truly reason, But
for those who can, the rules become nothing more than guidelines, And
live their lives governed not by rules but by reason.
- James McGuigan
Jul 17 '05 #2

"Amir Khawaja" <am**@gorebels.net> wrote in message
news:VlwSb.12553$QJ3.1377@fed1read04...
Reply-Via-Newsgroup wrote:
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 to have had any success so far - Can anyone suggest how I could stripslashes to every element without having to build my own
function?

(I don't want to use my own function when one already exists in PHP - In
part, because its more performance effective to use a precompiled function).
all helps.. via the newsgroup... is much apprecaited,

thanks
randelld


Try the following (untested) function:

function stripSlashes(&$var) {
if (is_string($var)) {
$var = stripslashes($var);
} else { // assume it is an array
foreach($var as $key => $value) {
stripSlashes($var[$key]);
}
}
}

--
Amir Khawaja.

Thanks for that... But I have already come up with that as a solution but
I'm sure there hsa got to be a more environmentally friendly method to go
easy on the system to do what I need to do... I'm sure something like
array_walk or array_map would do it in a single step...

Cheers
randelld
Jul 17 '05 #3

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

Similar topics

2
by: Sean | last post by:
I have two sites that i use for personal stuff (family, friends, photos). They are PHP sites butim not a programmer. They were setup by a friend who no longer helps with them. There are some...
0
by: Phil Powell | last post by:
<?php class Grad { var $dbFormExemptionArray = array(); function Grad ($id = '') { ...
1
by: comp.lang.php | last post by:
/** * Filter results according to given instruction * * @access private * @param object $result (reference) * @return object $filteredResult */ function &filterResults(&$result) { //...
6
by: steve | last post by:
Hi, I have never used array_walk, and quite frankly, cannot see why I should use it instead of foreach. Can someone shed some light on the cases where array_walk is the one to use, and what php...
2
by: lwoods | last post by:
I have the following function: function clean_form( &$from_check ) { if(is_array($from_check)){ array_walk(&$from_check,'clean_form'); return; } else { $value =...
13
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I direct someone to this FAQ? ----------------------------------------------------------------------- ...
12
by: Steve | last post by:
here's a quirk i can't seem to handle, just hack. since call-time by-reference is depreciated and i don't want to enable it in the php.ini, i'm kind of stuck when i want to pass userdata as an...
0
code green
by: code green | last post by:
Using the third parameter to pass the address of a user array to array_walk fills the user array with data. But once array_walk finishes executing the user array empties. Can any body explain this?...
3
by: DigitalBase | last post by:
Hi, I am trying to call a method on all objects in an array. What i am doing now :: $groups = $user->getGroups(); $newarray = array(); foreach ($groups as $group) { $newarray =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.