中山php|最优网络中山做网站 中山php建站

最优良人

Posts Tagged With: 数组

php多维数组的搜索

2012/12/17 at 20:48 » Comments (743)

1 php搜索多维数组的键值 如下面例子: $foo[1]['a']['xx'] = 'bar 1'; $foo[1]['b']['xx'] = 'bar 2'; $foo[2]['a']['bb'] = 'bar 3'; $foo[2]['a']['yy'] = 'bar 4'; $foo[3]['c']['dd'] = 'bar 3'; $foo[3]['f']['gg'] = 'bar 3'; $foo['info'][1] = 'bar 5'; 如果要查找 bar 3 怎么进行查找呢。有三个结果,而这三个结果都要,看下面的函数: ------------------------------------------------------------------------------------------------------------------------------- function array_search_re($needle, $haystack, $a=0, $nodes_temp=array()){ global ...more »

JS判断一个变量是否是数组以及循环数组

2011/08/14 at 02:52 » Comments (7)

JS判断一个变量是否是数组的方法 function isArray(o) { return Object.prototype.toString.call(o) === '[object Array]'; } //for in循环数组 var key; for (key in array) { } //for循环数组 var key; for (key =0;key< url.length;key++) { } more »

判断一个数组里是否都是空字符串

2011/08/14 at 01:10 » Comments (3)

有时我们要把一个全为空字符串组成的数组如:array('','','');当成是空对待,因为里面不含任何数据 使用empty()显然是不行的,因为里面包含了三个值,只是这些值都是空字符串,用count()也不可以 那么可以用一种变通的方式,先把数组用implode转换成字符串,再判断字符串是否为真就可以了: $a=array('',''); $a = implode('',$a);i f($a)'为真'; else echo '为假'; more »