0

I want to check each index of array if its value is numeric print next key

print_r($expkey);

gives

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
)

when [2] => 0 print phrase when [3] => 1 print use_system_locale

function numeric($key) {
$i=0;
if(is_numeric(key($key))){
 $i++;
 //if($i = ) incomplete code for function 
}
}
 numeric($expkey);

HOW TO DO IT ? THANK YOU FOR HELP

3 Answers 3

1

Loop through it and check. if succeed then print next value -

foreach($your_array as $key=>$value) {
    foreach($value as $key => $check_val) {
      if(is_numeric($check_val)) {
        echo $value[$ley+1];
      }
    }
}

You need to take care of the kays also.

Sign up to request clarification or add additional context in comments.

Comments

1
$i = 0;
foreach($expkey as $key->$value)
{
    if(is_numeric($value))
    {
        $next_val = $expkey[$i+1];
    }
    $i++;
}

1 Comment

Warning: Attempt to assign property of non-object
1

Just another answer:

<?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 />";
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.