php 数组。

WBOY
Release: 2016-06-23 14:16:02
Original
1155 people have browsed it

$d[]=array("淘宝","930852","http://","0");
$d[]=array("4399小游戏","698523","http://","0");
$d[]=array("天天有喜","689360","http://","0");
$d[]=array("火影忍者","462775","http://","0");
$d[]=array("中国好声音第二季","423689","http://","1");

如何去除二维数组 里$d[4][3] 为 0 的


回复讨论(解决方案)

$d[4][3]="";

楼主想问的到底是什么?是想去除$d[*][3] = "0"的还是想将$d[4][3] 置为"0"?

楼主想问的到底是什么?是想去除$d[*][3] = "0"的还是想将$d[4][3] 置为"0"?
我表达不够准确。
是去除$d[*][3] = "0"的

var_dump(array_filter($d, "foo"));function foo($v){    return $v[3]!=='0';}
Copy after login
Copy after login

你的 $d[0][3]、$d[1][3]、$d[2][3]、$d[3][3] 都为 0,而 $d[4][3] 为 1
你是要删除哪些为 0 的元素吗?
但这不合规则,当用 $d[0][3] 访问时就要八错的 Notice: Undefined offset: 3

考虑清楚再提问

var_dump(array_filter($d, "foo"));function foo($v){    return $v[3]!=='0';}
Copy after login
Copy after login

出除了 之后数组里面的键怎么排序
Array ( [4] => Array ( [0] => 中国好声音第二季 [1] => 423689 [2] => http://[3] => 1 ) )
数组从4开始了

$ar=array_filter($d, "foo");
print_r(array_values($ar));
function foo($v){
    return $v[3]!=='0';
}

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