Home > Backend Development > PHP Tutorial > php轮换数组内元素

php轮换数组内元素

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:54:29
Original
1122 people have browsed it

php替换数组内元素

php中虽然处理数组的函数特别多,但是有的函数还要我们自己封装,譬如替换数组里面的元素:

下面是替换数组的键=>KEY值:

<?php $arr = array();$array = array(    0 => array(shop_name=>1,shop_id=>2),    1 => array(shop_name => 2, shop_id=>3));for($i=0; $i<count>';print_r ($arr);echo '</count>
Copy after login
';?>

下面实例是封装的一个方法:

开发小技巧实例程序,使用递归替换数组中的内容。

把数组内的替换成{ }。

你可以根据实际情况去使用这个函数。替换数组内的元素还是很方便的;

<?php $arr = array("<小刚>","","","","");    function arrContentReplact($array)    {        if(is_array($array))        {            foreach($array as $k => $v)            {                $array[$k] = arrContentReplact($array[$k]);            }        }else        {            $array = str_replace(array(''), array('{', '}'), $array);        }        return $array;    }       $arr3 = arrContentReplact($arr);       echo "<pre class="brush:php;toolbar:false">";    print_r($arr3);    echo "
Copy after login
";?>

以上例子输出的结果为:

Array(    [0] => {小刚}    [1] => {小晓}    [2] => {小飞}    [3] => {小李}    [4] => {小红})
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
Latest Issues
How to create an array within an array?
From 1970-01-01 08:00:00
0
0
0
php array
From 1970-01-01 08:00:00
0
0
0
Array to array
From 1970-01-01 08:00:00
0
0
0
php array rotation
From 1970-01-01 08:00:00
0
0
0
array
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template