[英]php - multidimensional array regex search and print out partial array to look at structure
我有这个数组结构,它存储在变量$ xxx中
Array
(
[xyz] => Array
(
[1] => 3
[0] => s
)
[d2s] => Array
(
[a] => 96
[d] => 4
)
...
)
它是一个长数组,我不想把全部内容都花光了,如何只打印前5个(第一维)值和第二维值?
其次,如果我希望该数组在FIRST维中仅包含字母,我该如何删除不符合该要求的值或保留符合该要求的值? 这样我的最终数组将是
Array
(
[xyz] => Array
(
[1] => 3
[0] => s
)
...
)
TIA
要仅输出前5个元素,请使用array_slice
:
array_slice($arr, 0, 5)
删除索引中包含非字母字符的所有元素。
foreach ($arr AS $index => $value) {
// Remove the element if the index contains non-alpha characters
if (preg_match('/[^A-Za-z]/', $index))
unset($arr[$index]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.