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

function works, array_walk fails

<?php

class Grad {

var $dbFormExemptionArray = 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->dbFormExemptionArray =
array('instant_messenger_service_id' => 'instantMessenger',
'is_citizen' => 'citizen',
'salary_range' => 'salary',
'grad_preferred_org_description' =>
'gradPreferredOrgDesc',
'federal_agencies' => 'agencies',
'has_security_clearance' => 'hasClearance',
'security_clearance_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_accomplishments' => 'jobDuties',
'languages_other' => 'language_other'
);

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

function dbNameToFormName($formField) { // STRING "METHOD"
$formDBExemptionArray = array_flip($this->dbFormExemptionArray);
if (array_search($formField, $formDBExemptionArray) !== false
&amp;&amp; array_search($formField, $formDBExemptionArray) !== null) {
return array_search($formField, $formDBExemptionArray);
} else {
$dbNameArray = explode('_', $formField);
$classMethodCompartmentArray = array();
$classMethodCompartmentArray[0] = $this;
$classMethodCompartmentArray[1] = 'arrayStrToUpper';
array_walk($dbNameArray, $classMethodCompartmentArray);
$dbNameArray[0] = strtolower($dbNameArray[0]);
return implode('', $dbNameArray);
}
}

}

$grad =&amp; new Grad;

foreach(array('ethnicity_id', 'ethnicity_other', 'start_date',
'fname', 'career_level_id') as $key => $val) {
print_r("val = $val and converted it is = " .
$grad->dbNameToFormName($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 1947

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

Similar topics

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...
0
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...
3
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
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...
1
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) { ...
7
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
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...
4
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. ...
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...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.