The traversal array in PHP finds whether an array element exists with the current string, if it does not exist, outputs the current string, and if present, the key value of the output array

Source: Internet
Author: User
Tags uuid

  
   '规则缓冲清除',    'Starting replication'=>'开始规则',    'Wait -> Brk'=>'镜像状态改变,由等待到停止状态',    'OK -> Wait'=>'镜像状态改变,由OK到等待状态',);$logs = sd_get_log_sys_by_uuid(uuid);for($i=0; $i<$count(logs); $i++) {    if($lang_Log[$logs[$i]]){        echo $lang_Log[$logs[$i]];    }else{        foreach ($lang_Log as $k=> $v) {            $pos = strpos($logs[$i], $k);            if($pos !== false){                echo $v;                break;            }        }     }}?>

All I want to do is iterate over the array to find out if the array element exists with the current string, if it does not exist, output the current string, and if present, the output array's key value.
is the translation function.

1. Determine if the log has a corresponding Chinese in the array (because the log is dead).
2. Determine if the log part string has a corresponding Chinese (some logs are statements that contain variables, so you need to match them with some strings and then translate them).
3. Because the outer layer has a logs array of loop statements, so use break, do not exit.

Reply content:


  
   '规则缓冲清除',    'Starting replication'=>'开始规则',    'Wait -> Brk'=>'镜像状态改变,由等待到停止状态',    'OK -> Wait'=>'镜像状态改变,由OK到等待状态',);$logs = sd_get_log_sys_by_uuid(uuid);for($i=0; $i<$count(logs); $i++) {    if($lang_Log[$logs[$i]]){        echo $lang_Log[$logs[$i]];    }else{        foreach ($lang_Log as $k=> $v) {            $pos = strpos($logs[$i], $k);            if($pos !== false){                echo $v;                break;            }        }     }}?>

All I want to do is iterate over the array to find out if the array element exists with the current string, if it does not exist, output the current string, and if present, the output array's key value.
is the translation function.

1. Determine if the log has a corresponding Chinese in the array (because the log is dead).
2. Determine if the log part string has a corresponding Chinese (some logs are statements that contain variables, so you need to match them with some strings and then translate them).
3. Because the outer layer has a logs array of loop statements, so use break, do not exit.

Why don't you go else ?
You cycle through every word, the first of the loops is rep-cache during mirror is cleard ,
exists in $s it?
不存在
Can't we go else ?

Shipping not running exit; ?
运行
And not continue to execute?
不继续
Do you check the following words?
不检查

foreach ($lang_Log as $k=> $v) {    $pos = strpos($s, $k);    if($pos !== false){        echo $v;        break;    

$s = "mirror return 0, Peer 94, Bytes recv [en/de] [2005667596/2005667596 = 100]";
foreach ($lang _log as $k = + $v) {

$pos = strpos($s, $k);if($pos !== false){    echo 'value = ' .  $v . "
;}else{ echo 'key = ' . $k . "
;}

}

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.