Op 14 jan 2011, om 02:53 heeft Daniel Friesen het volgende geschreven:
> On 11-01-13 05:35 PM, [email protected] wrote:
>>>>>>> "DF" == Daniel Friesen<[email protected]> writes:
>> DF> Using in_array and array_diff on an exploded array should work
>> fine.
>> OK, but that would take several times as many lines than my current:
>>
>> foreach(array_keys($links['namespaces']) as $ns){
>> if(strpos($ns,'talk')!==false){
>> if('new'==$links['namespaces'][$ns]['class']){
>> unset($links['namespaces'][$ns]);}}}
>>
>> and force me to hardwire in more specific knowledge of your current
>> structure, no?
> I'm talking about on class strings.
> `in_array('new', explode(' ', $links['namespaces'][$ns]['class']));`
> rather than `'new'==$links['namespaces'][$ns]['class']` which will
> break
> should another class be added to that item.
> And you can use array_diff in a similar way to check for multiple
> classes
>
> Still, I wish we never started using classes like this in the first
> place. These would have been much better off as array keys.
>
> ~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://
> daniel.friesen.name]
I'm not sure about the context but I think using foreach as key =>
value makes more sense
in instead of getting array_keys and getting the value by accessing
the array (again) with the key.
See the following:
foreach( $links['namespaces'] as $ns => $value ) {
if( strpos( $ns, 'talk' ) !== false ){
if( in_array( 'new', explode(' ', $value['class'] ) ) ) {
unset( $links['namespaces'][$ns] );
}
}
}
Just fyi: The number of lines doesn't always represent performance gain.
And, from what I can see this loop would mark a namespace called
"Stalk" incorrectly as "talk namespace".
For example
* SiteName: StalkBot Wiki
* Project namespace: StalkBot
* Project talk namespace: StalkBot_talk
or any word in any language containing the letters 'talk'.
_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l