473,775 Members | 2,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

function works, array_walk fails

<?php

class Grad {

var $dbFormExemptio nArray = array();

function Grad ($id = '') {

/*----------------------------------------------------------------------------------------------------------------------
Do note that if you are generating arrays that will not have
their values dynamically placed into the
db insert or update statements you *MUST* place the name
'array' or 'Array' (or any variant capitalization
you like) into the name of the object array else it will be
assumed to be part of the get_class_vars( ) array
call dynamically parsed to produce the SQL strings
-----------------------------------------------------------------------------------------------------------------------*/

// USED FOR SPECIAL CASES WHEN GENERATING SQL STATEMENTS TO
COMPARE FORM NAMES TO DB NAMES OR VICE VERSA
$this->dbFormExemptio nArray =
array('instant_ messenger_servi ce_id' => 'instantMesseng er',
'is_citizen' => 'citizen',
'salary_range' => 'salary',
'grad_preferred _org_descriptio n' =>
'gradPreferredO rgDesc',
'federal_agenci es' => 'agencies',
'has_security_c learance' => 'hasClearance',
'security_clear ance_level_id' => 'clearanceID',
'grad_ideal_job ' => 'idealJob',
'language_id' => 'languages',
'language_rank_ id' => 'proficiency',
'salary' => 'jobSalary',
'start_date' => 'jobStartDate',
'end_date' => 'jobEndDate',
'hours_per_week ' => 'jobHours',
'job_duties_acc omplishments' => 'jobDuties',
'languages_othe r' => 'language_other '
);

}
function arrayStrToUpper (&amp;$elemen t) { // PRIVATE STRING
"METHOD" FOR array_walk
$allCapsArray = array('id', 'gpa');
if (in_array($elem ent, $allCapsArray)) return
strtoupper($ele ment);
return ucfirst($elemen t);
}

function dbNameToFormNam e($formField) { // STRING "METHOD"
$formDBExemptio nArray = array_flip($thi s->dbFormExemptio nArray);
if (array_search($ formField, $formDBExemptio nArray) !== false
&amp;&amp; array_search($f ormField, $formDBExemptio nArray) !== null) {
return array_search($f ormField, $formDBExemptio nArray);
} else {
$dbNameArray = explode('_', $formField);
$classMethodCom partmentArray = array();
$classMethodCom partmentArray[0] = $this;
$classMethodCom partmentArray[1] = 'arrayStrToUppe r';
array_walk($dbN ameArray, $classMethodCom partmentArray);
$dbNameArray[0] = strtolower($dbN ameArray[0]);
return implode('', $dbNameArray);
}
}

}

$grad =&amp; new Grad;

foreach(array(' ethnicity_id', 'ethnicity_othe r', 'start_date',
'fname', 'career_level_i d') as $key => $val) {
print_r("val = $val and converted it is = " .
$grad->dbNameToFormNa me($val) . "<P>");
}

$grad = null;

?>
This block of code fails to do what it is supposed to do: take a
patterned string and convert it to being a mixed-case variable.

Here is the actual output if you ran it now:
val = ethnicity_id and converted it is = ethnicityid

val = ethnicity_other and converted it is = ethnicityother

val = start_date and converted it is = jobStartDate

val = fname and converted it is = fname

val = career_level_id and converted it is = careerlevelid
Here is the way the output is SUPPOSED to look like instead:
val = ethnicity_id and converted it is = ethnicityID

val = ethnicity_other and converted it is = ethnicityOther

val = start_date and converted it is = jobStartDate

val = fname and converted it is = fname

val = career_level_id and converted it is = careerLevelID
the function itself works perfectly, however, as a callback function
it seems to do nothing in array_walk, furthermore, array_walk returns
a 1 meaning the results are valid. Nonetheless, the array elements
remain unchanged, nor is any scalar variable placed into the original
class method that has array_walk.

This is the second time array_walk has failed to do for me what it is
advertised to do (see
http://us2.php.net/manual/en/function.array-walk.php). Is there an
alternative to array_walk in PHP or do I have to search outside of PHP
to do such a simple yet infuriating task?

Phil
Jul 17 '05 #1
0 1966

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

Similar topics

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
3051
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. --
0
380
by: Jay Allard | last post by:
Hello I posted this in the vb.net group on the 2/25/2004, but didn't get any response. Here's attempt 2. Does anyone know of a more appropriate place to post this? One new piece of information: It fails on any method that it happens to hit first. I juggled the methods a bit, and it just doesn't matter. As soon as the XslTransform hits an extension function, it fails with an invalid argument exception.
3
1510
by: Zac Panepucci | last post by:
Hello There, I am using the following constructs to parse named arguments: function whatever() { if (this.yo) { if(this.yo=='man') alert('wuzup'); else
6
4410
by: Bill Rubin | last post by:
The following code snippet shows that VC++ 7.1 correctly compiles a static member function invocation from an Unrelated class, since this static member function is public. I expected to compile the same invocation from a DistantlyRelated class. What actually happened was that the compiler produced: error C2247: 'A::function' not accessible because 'CloselyRelated' uses 'private' to inherit from 'A' I'm guessing that the above compiler...
1
1174
by: comp.lang.php | last post by:
I thought my function would have accomplished just that: if (!function_exists('resetCSV')) { function &resetCSV($fullFileName, $path, $willClearFile = false) { /*------------------------------------------------------------------------------------------------------------------------------------------ New 8/23/2006: This function will either reset the second column of a CSV file (clearing the column of values) or clear file if
7
10291
by: gregp1 | last post by:
Hi guys, Here's the code I'm to refer to: <html> <body> .... <form method="get" action="http://www.google.com/search" name="google" />
7
1966
by: howmanymiles | last post by:
I am currently writing a program which works out student marks and outputs the passes and fails two files. I have written some code but it does seem work as no names are displayed and according to this everybody has passed. My switch function is working, so why dont the other functions work? I have been creating new constructors, adding to the student class and allsorts but I just keep getting errors. My code is below #include <cstdlib>...
4
1581
by: lawpoop | last post by:
Hello all - I would like to use the is_numeric() function to check each element of an array. I am just looking for a false if any element is not numeric, or a true if each element is numeric. Can I do this with a single function in a single like, or do I have to do a foreach{ ... break() } structure?
0
9622
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, 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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10270
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...
0
10109
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9916
tracyyun
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8940
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...
0
5361
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...
1
4018
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.