<?php
include 'wp-load.php';

function wp_slash_1( $value ) {
	if ( is_array( $value ) ) {
		foreach ( $value as $k => $v ) {
			if ( is_array( $v ) ) {
				$value[$k] = wp_slash_1( $v );
			} else {
				$value[$k] = addslashes( $v );
			}
		}
	} else {
		$value = addslashes( $value );
	}

	return $value;
}

function wp_slash_2( $value ) {
	if ( is_array( $value ) ) {
		$value = array_map( 'wp_slash_2', $value );
	} else {
		$value = addslashes( $value );
	}

	return $value;
}

$simple_array = array(
	'a' => "I can't see, isn't that it?",
	'b' => "I can't see, isn't that it?",
	'c' => "I can't see, isn't that it?",
);

$nested_arrays = array(
	'a' => array(
		'a' => array(
			'a' => "I can't see, isn't that it?",
			'b' => "I can't see, isn't that it?",
			'c' => "I can't see, isn't that it?",
		),
		'b' => "I can't see, isn't that it?",
		'c' => "I can't see, isn't that it?",
	),
	'b' => "I can't see, isn't that it?",
	'c' => "I can't see, isn't that it?",
);

foreach ( array( $simple_array, $nested_arrays ) as $array ) {

	timer_start();

	for ( $i = 0; $i < 1000000; $i++ ) {
		wp_slash_1( $array );
	}

	printf( "%s seconds.\n", timer_stop( 0, 3 ) );

	timer_start();

	for ( $i = 0; $i < 1000000; $i++ ) {
		wp_slash_2( $array );
	}

	printf( "%s seconds.\n", timer_stop( 0, 3 ) );
}
