Hey, I just impressed myself a little. I thought this code was going to take a little longer than it did, but I got it essentially on the first try, and quickly.
<?php
function merge(&$a, &$b){
$keys = array_keys($a);
foreach($keys as $key){
if(isset($b[$key])){
if(is_array($a[$key]) and is_array($b[$key])){
merge($a[$key],$b[$key]);
}else{
$a[$key] = $b[$key];
}
}
}
$keys = array_keys($b);
foreach($keys as $key){
if(!isset($a[$key])){
$a[$key] = $b[$key];
}
}
}
?>
I actually got it on the second try, but only because I forgot that second part that copies the values for the keys that didn't exist in the first array from the second (duh).
Anyway, I figured it was neat, so I blogged it.
I was going to go into a longer post about why none of array_merge, array_merge_recursive, and the normal array '+' operator that I didn't even know about did what I wanted, but I still have to study for my probability and statistics exam tomorrow.
Update: I knew I should have waited to post this. There's a bug if the two arrays don't have the same structure. In other words, if one has an array for a given key where the other has a scalar, it won't work. But I think it's only if the first array has a scalar and the second one has an array, and not the other way around. I'll post a corrected version here when I get it right 
Update: Ok, fixed. Neglected to check that both $a[$key] and $b[$key] were arrays. So now it works exactly like I expected it to. However, because of how my CMS works, the way I planned it isn't actually the way I need it to work
So I'll have to deal with that later...
Update: Over in the HiveMinds forum there's a discussion of this code:
Now, I took a couple passes over the code, and it looks like to me that if a value for the same key exists in both arrays, the value from array b will overwrite the value in array a. What am I missing here? How is this truly a merge? I see how the second block adds to a things that don't exist in b, but the first code block (other than the section that calls merge recursively if both keys are really arrays) seems to overwrite the slot in a with the value in b. Maybe thats just what he wants it to do. Am I missing something here? I'm sure its right in front of me and I'm just not seeing it.
That's what I intended. I mentioned above that I didn't have time to explain why PHP's built in array_merge and array_merge_recursive functions, and the built-in array '+' operator weren't what I needed. But what the poster describes is exactly what I intended. Notice, however, that this code does in fact behave similarly to the array_merge function and the built-in array '+' operator (except maybe for numeric indices -- I have to make sure), except that those aren't recursive.
The reason I needed this type of merge function is because, in my CMS, "more specific" settings overwrite "less specific" settings as I parse through the configuration file. Unfortunately, this code doesn't do what my CMS needs when the arrays have numeric indices.
Update: check out the new version.
Bill Humphries, who somehow frames this in terms of Stalin's "useful idiots", points to what I found to be a pretty insightful article from the New York Times on the increasing tendency among young people to be against abortion. For some reason it's in the "Fashion and Style" section.
Experts offer a number of reasons why young people today seem to favor stricter abortion laws than their parents did at the same age. They include the decline in teenage pregnancy over the last 10 years, which has reduced the demand for abortion. They also cite society's greater acceptance of single parenthood; the spread of ultrasound technology, which has made the fetus seem more human; and the easing of the stigma once attached to giving up a child for adoption.
The most commonly cited reason for the increasingly conservative views of young people is their receptiveness to the way anti-abortion campaigners have reframed the national debate on the contentious topic, shifting the emphasis from a woman's rights to the rights of the fetus.
Britni Hoffbeck, another speech student at Red Wing High who opposes abortion, and who says her views are more conservative than those of her parents, put her argument succinctly: "It's more about the baby's rights than the woman's rights."
Some young people who oppose abortion, and who were born after the Roe v. Wade decision in 1973 declared that were is a constitutional right to abortion, have adopted a new rhetoric. One of them is Kelly Kroll, a junior at Boston College and president of American Collegians for Life, who says she is a "survivor of the abortion holocaust" because she was adopted.
The article also cites some interesting statistics about teenage pregnancy rates and public opinion.
Update: From Technorati I ran across a great post about this article from David Mills at tourchstonemag.com. Unfortunately, his blog is all messed up regarding permalinks. So go here and it should probably be at the top.
So as I said, the first quarter of the article is cheering, because it says that young people are increasingly pro-life. The rest of the article is revealing, because it shows how our pro-choicers think and the extent to which they must deny the reality of any contradictory moral insight and treat people who disagree with them as having been manipulated or conditioned into believing what they believe.
Nice, that sounds like he's talking right to Bill 
The last three-quarters of the article try to explain this shift, in other words to explain it away. The article nowhere suggests that young people may be making a rational moral decision. It assumes the pro-life youth must believe what they believe for other reasons.
Anyway, go to the link and read the rest. Unfortunately, David doesn't have an RSS feed, so it's unlikely I'll read his site again. That makes me sad.
I never really watched X-Files, but vaguely recognize the overall story when people mention it. Anyway, check out this comment on Scott's site that completely nails Smallville.
Via Raible Designs, check out this WebWork Tutorial. It does make it look easy.
After reading this I think I'm just about conceptually ready to write the "Actions" parts of my CMS that do form processing, validation, etc. Then I'll finally be able to write the backend for my CMS.
Some of the things in that tutorial make me jealous of some of the features PHP doesn't have. Like clean iterators. Instead of being able to say
#foreach($error in $errors)
I have to say stuff like:
while($error = $errors->next()){
but PHP5 will allow you to make standard iterators.
Other stuff that PHP 5 will have that I want are interfaces/abstract classes and access protection (PPP). In my CMS I've been wanting to have similar classes derive from a base class (all Modules are derived from Module, all Iterators are derived from Iterator), etc. Regarding the Actions in this article, I'd like to have all actions inherit from a base Action class so that all Action subclasses are forced to implement methods like "validate", etc. But there's so much less incentive when there's nothing to force a derived class to implement methods in an abstract base class or interface.
So yeah, I'm looking forward to PHP 5.
Some Kung-Fu Wisdom from James:
Student: Master, tell me something that will make me laugh if I am crying?
Master: Just contemplate the meaning of these words: "And this too shall pass."
Student: Oh, I see, master. Well, Master, what will make me cry if I am laughing?
Master: Just contemplate the meaning of these words: "And this too shall pass." When you truly begin to understand, you will be enlightened, and enlightenment does not pass.
Update (Nov 1, 2005): Also see GZY : In Search of Solomon's Ring.
Hey, that was fast. Version 0.1 of Minotaur is available in Windows binaries. Not much to see here yet (read this review), but hopefully there will be good things to come.
Court rejects death penalty for raping children - Yahoo! News
:)...
Keith: Jul 4, 11:32am