質問

What I've Tried

I've gone through the following PHP Extension tutorials: http://devzone.zend.com/303/extension-writing-part-i-introduction-to-php-and-zend/ http://php.webtutor.pl/en/2011/07/07/how-to-create-php-extensions-in-c-part-i-adding-simple-function/ And all of them are great resources for adding new functions.

I've created a few simple extensions that add simple functions. Mostly hello_world() type extensions. I've tried browsing the source code and everything but I just can't seem to find what I need.

What I Need

I need help or a point in the right direction on how I can change php functionality. I'm trying to extend the syntax for a foreach. This is more of a learning opportunity then I think changing the syntax for a foreach is a good idea.

1) How do I find the current implementation of foreach in the current PHP source code? 2) How do I write and extension to change it?

The End Goal

Every time I write an array where I want a unique set of numbers instead of putting the numbers in the values and doing an array search I put them in the keys and set the value as true. When I do a foreach I don't care about the keys. so I want to create the following syntax:

foreach ($myArray as $key => ) {
    // Do stuff here    
}

Any help would be greatly appreciated. Thanks!

役に立ちましたか?

解決

You cannot change PHP's core behaviour using an extension. If you want to change the foreach loop you need to change core components of PHP and recompile it. It's up to you to find out what you'll have to change. (That's the fun)

However you may just doing this:

foreach (array_keys($myArray) as $key) {
    // Do stuff here    
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top