Paste P6435

php foreach vs array_filter
ActivePublic

Authored by dcausse on Dec 6 2017, 2:03 PM.
$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
)
dcausse created this paste.Dec 6 2017, 2:03 PM