Hi, I am basing this upon my study of the array_search and array_keys
functions in www.php.net and www.zend.com and www.nyphp.org.
I have this array, $this->propertyArray, which I have passed into a
class as a mocked-up version of the same formatting as _GET and _POST
arrays inasmuch as the keys are variable names and vals are the
variable values. Here is the print_r printout of $this->propertyArray
for example:
Array (
[birth_month] => 10
[birth_day] => 01
[birth_year] => 1964
[0] => 4
)
I have a local array, $keyIndexArray, which I derived by doing this:
$keyIndexArray = array_keys($this->propertyArray);
this produces the following array which I can show using print_r:
Array (
[0] => birth_month
[1] => birth_day
[2] => birth_year
[3] => 0
)
I produce $keyIndexArray in order to know the ordinal position of each
key/val pair in propertyArray since I will be doing a particular
function upon each element in propertyArray depending SOLELY on its
position (the keys and vals can literally be anything at all!). So I
figured the easiest way to do it is to create a local enumerative
array so that I have a "static" value by which to pull from something
that tells me "Hey, this is a month", or "Hey, this is a year".
I can get what I want by doing this:
foreach ($this->propertyArray as $key => $val) {
switch (array_search($key, $keyIndexArray)) {
case '2': // It's a year, do year stuff
break;
case '0': // It's a month, do month stuff
....
}
}
However, for some reason, for the switch statement I am always getting
'3' every single time, verified by this print_r on key and val and
array_search:
key = birth_month and val = 10 and array_search for birth_month in
keyIndexArray = 3
Here are my online references:
http://us2.php.net/manual/en/function.array-search.php
http://us2.php.net/manual/en/function.array-keys.php
http://us2.php.net/manual/en/control...res.switch.php
Maybe I missed something in my simple plan, that is, parse through
$this->propertyArray and do month stuff on the first one, day stuff
on the second one, year stuff on the third one, etc.
Phil
PS: THIS IS *****NOT***** HOMEWORK!!!!!!!!!!! Someone had a baby fit
when I posted stuff like this earlier so this is a disclaimer.