473,801 Members | 2,207 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2961
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($v ar);
} else { // assume it is an array
foreach($var as $key => $value) {
stripSlashes($v ar[$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.1255 3$QJ3.1377@fed1 read04...
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($v ar);
} else { // assume it is an array
foreach($var as $key => $value) {
stripSlashes($v ar[$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
1851
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 things with the Gallery upload and topics that just don't work anymore. I suspect it would be trivial for someone who knows PHP to fix. I am willing to pay $100 a year for someone to keep the sites up and running...minimal time is needed. ...
0
1967
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
1
1822
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) { // STATIC OBJECT ARRAY METHOD global $section;
6
3052
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 developers where thinking when they coded this operator. Thanks. --
2
2177
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 = str_replace(array("\r","\n","Content-Type:"),"",$from_check); }
13
2074
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I direct someone to this FAQ? ----------------------------------------------------------------------- This document is posted to clj very frequently. There should be no reason to direct someone to it. However, if someone asks a question answered in this FAQ or in one of the resources listed herein, please let them know their question is answered...
12
2961
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 array byref that is initially = array(). // the array being walked $numbers = array(1, 56, 999, 1000, 28, 65); // the work-around
0
1010
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? $assocPriceLists = array(); //Create price lists lookup table if(array_walk($priceLists, 'createAssoc', $assocPriceLists)) { print_r($assocPriceLists); //Prints Array(). assocPriceLists is empty function...
3
5016
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 = $group->getId();
0
10516
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10262
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9101
agi2029
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7589
isladogs
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6829
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5479
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5616
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2959
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.