Ec (2 ); **************************************** * ********************* & nbsp; 02 & nbsp; * & nbsp; 03 & nbsp; * & nbsp; use a specific function to process all elements in the array & nbsp; 04 & nbsp; * & nbsp; @ param & nbsp; & script ec (2); script
/*************************************** ***********************
02 *
03 * use a specific function to process all elements in the array
04 * @ param string & $ array the string to be processed
05 * @ param string $ function the function to be executed
06 * @ return boolean $ apply_to_keys_alsoApplicationTo the key
07 * @ access public
08 *
09 *************************************** **********************/
10 function arrayRecursive (& $ array, $ function, $ apply_to_keys_also = false)
11 {
12 foreach ($ array as $ key => $ value ){
13 if (is_array ($ value )){
14 arrayRecursive ($ array [$ key], $ function, $ apply_to_keys_also );
15} else {
16 $ array [$ key] = $ function ($ value );
17}
18
19 if ($ apply_to_keys_also & is_string ($ key )){
20 $ new_key = $ function ($ key );
21 if ($ new_key! = $ Key ){
22 $ array [$ new_key] = $ array [$ key];
23 unset ($ array [$ key]);
24}
25}
26}
27}
28
29 /************************************** ************************
30 *
31 * convert an array to a JSON string (compatible with Chinese characters)
32 * @ param array $ array to be converted
33 * @ return string the converted json string
34 * @ access public
35 *
36 *************************************** **********************/
37 function JSON ($ array ){
38 arrayRecursive ($ array, 'urlencode', true );
39 $ json = json_encode ($ array );
40 return urldecode ($ json );
41}