[英]Check each index of array if value of index is numeric print next index value - PHP
我想检查数组的每个索引,如果其值为数字,则打印下一个键
print_r($expkey);
给
Array
(
[0] => ew-language
[1] => en
[2] => 0
[3] => phrase
[4] => locale
)
Array
(
[0] => ew-language
[1] => en
[2] => phrase
[3] => 1
[4] => use_system_locale
)
当[2] => 0
打印phrase
时[3] => 1
打印use_system_locale
function numeric($key) {
$i=0;
if(is_numeric(key($key))){
$i++;
//if($i = ) incomplete code for function
}
}
numeric($expkey);
怎么做 ? 谢谢你的帮助
循环浏览并检查。 如果成功,则打印下一个值-
foreach($your_array as $key=>$value) {
foreach($value as $key => $check_val) {
if(is_numeric($check_val)) {
echo $value[$ley+1];
}
}
}
您还需要照顾kay
。
$i = 0;
foreach($expkey as $key->$value)
{
if(is_numeric($value))
{
$next_val = $expkey[$i+1];
}
$i++;
}
只是另一个答案:
<?php
function getValueNextToFirstNumeric($arr) {
for($i=0; $i<count($arr); $i++) {
if(is_numeric($arr[$i]) && isset($arr[$i+1]))
return $arr[$i+1];
}
return null;
}
// Your array:
$arr = array
(
['ew-language', 'en', 0, 'phrase', 'locale'],
['ew-language', 'en', 'phrase', 1, 'use_system_locale'],
['ew-language', 'en', 2, 'phrase', 'decimal_point']
);
foreach($arr as $a)
echo getValueNextToFirstNumeric($a) ."<br />";
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.