Home > Backend Development > PHP Tutorial > 怎样去除数组中数字索引?

怎样去除数组中数字索引?

WBOY
Release: 2016-06-06 20:13:51
Original
1412 people have browsed it

通过print_r打印数组,结果类似这样

<code>Array
(
    [name] => jack
    [0] => jack
    [age] => 18
    [1] => 18
)</code>
Copy after login
Copy after login

怎么去除数字索引"0"、"1",让其变为这样的数组

<code>Array
(
    [name] => jack
    [age] => 18
)</code>
Copy after login
Copy after login

回复内容:

通过print_r打印数组,结果类似这样

<code>Array
(
    [name] => jack
    [0] => jack
    [age] => 18
    [1] => 18
)</code>
Copy after login
Copy after login

怎么去除数字索引"0"、"1",让其变为这样的数组

<code>Array
(
    [name] => jack
    [age] => 18
)</code>
Copy after login
Copy after login

这个数组哪儿来的?如果是数据库的查询结果,那么在获取数据的时候可以避开啊。在进行数据查询的时候可以规定返回值的格式,比如mysql_fetch_row支持MYSQL_ASSOC,MYSQL_NUM 和 MYSQL_BOTH,第一个表示返回字段名=>值的格式,第二个表示返回数字索引=>值的格式,第三种就是返回你现在遇到的这种格式。
所以,看看你调用的查询方法的说明,换个参数就行了。

楼上正解,如果是从数据库获取数据可以避免,不是的话自己可以写个方法过滤一下咯。

如果是sql serve 怎么解决?

Related labels:
php
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