Page MenuHomePhabricator

php foreach vs array_filter

Authored By
dcausse
Dec 6 2017, 2:03 PM
Size
1 KB
Referenced Files
None
Subscribers
None

php foreach vs array_filter

$namespaces = array_filter( $namespaces, function ( $k, $v ) {
wfDebug( "via array_filter: " . gettype( $v ) . " : " . gettype( NS_MAIN ) );
return true; // $v !== NS_MAIN;
}, ARRAY_FILTER_USE_BOTH );
wfDebug( "VIA reset: " . gettype( reset( $namespaces ) ) );
wfDebug( "DUMP:" . print_r( $namespaces, true ) );
foreach ( $namespaces as $k => $v ) {
wfDebug( "$k => $v | " . NS_MAIN );
wfDebug( "via foreach:" . gettype( $v ) . " : " . gettype( NS_MAIN ) );
if ( $v === NS_MAIN ) {
wfDebug( "UNSET" . print_r($namespaces, true) );
unset( $namespaces[$k] );
}
}
wfDebug( print_r($namespaces, true) );
will output:
2017-12-06 13:59:20 cirrustestwiki wfDebug DEBUG: via array_filter: integer : integer
2017-12-06 13:59:20 cirrustestwiki wfDebug DEBUG: VIA reset: string
2017-12-06 13:59:20 cirrustestwiki wfDebug DEBUG: DUMP:Array
(
[0] => 0
)
2017-12-06 13:59:20 cirrustestwiki wfDebug DEBUG: 0 => 0 | 0
2017-12-06 13:59:20 cirrustestwiki wfDebug DEBUG: via foreach:string : integer
2017-12-06 13:59:20 cirrustestwiki wfDebug DEBUG: Array
(
[0] => 0
)

File Metadata

Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5166405
Default Alt Text
php foreach vs array_filter (1 KB)

Event Timeline