Home > Backend Development > PHP Tutorial > php怎么将数组中每个元素都用urlencode转一下格式

php怎么将数组中每个元素都用urlencode转一下格式

WBOY
Release: 2016-06-13 13:27:25
Original
962 people have browsed it

php如何将数组中每个元素都用urlencode转一下格式
php中有一数组如下:
$array = array(
'test'=>'我是测试',
  'hello'=>'你好',
  'yahoo'=>'雅虎'
);
print_r($array);
运行输出为:Array ( [test] => 我是测试 [hello] => 你好 [yahoo] => 雅虎 )

问题是:
如何将数组转为
$array = array(
'test'=>urlencode('我是测试'),
  'hello'=>urlencode('你好'),
  'yahoo'=>urlencode('雅虎')
);
使得输出变为:Array ( [test] => %CE%D2%CA%C7%B2%E2%CA%D4 [hello] => %C4%E3%BA%C3 [yahoo] => %D1%C5%BB%A2 )

哪位知道的话帮忙解答一下,先谢谢了~~

------解决方案--------------------

PHP code
$array = array_map('urlencode', $array); <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template