Home > Backend Development > PHP Tutorial > 如何把数组的key索引转化成数字索引

如何把数组的key索引转化成数字索引

WBOY
Release: 2016-06-13 13:34:25
Original
1592 people have browsed it

怎么把数组的key索引转化成数字索引?
比如我从ini文件中读取的信息是个一维数组:
这是我的ini文件
[web]
host = localhost
connuser = root
connpwd = root
conndb = myoffice

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
//读取文件
    function ReadConfig($filename)
    {
        if(file_exists($filename) == false)
        {
            //echo "<br>文件".$filename."不存在!<br>";
            return NULL;
        }
        return parse_ini_file($filename,true);
    }

//测试
    $Setting = array();
    $res = array();
    $Setting = ReadConfig("webconfig.ini");
    print_r($Setting);

Copy after login

我不想要这种带有key的数组,因为十分不习惯,希望能转化成这样--使用数组数字下标索引号0,1,2,3,。。。
$res[0] == localhost;
$res[1] == root;
...
而不是$Setting["host"] == localhost这样的形式?

------解决方案--------------------
array_values();
------解决方案--------------------
你有
return parse_ini_file($filename,true);
所以返回的数组是二维数组
PHP code
Array
(
    [web] => Array
        (
            [host] => localhost
            [connuser] => root
            [connpwd] => root
            [conndb] => myoffice
        )

) <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