Php traverses the array to find whether the array element exists with the current string. if it does not exist, the current string is output. if it exists, the key value of the array is output.

Source: Internet
Author: User
{Code...} What I want to do is to traverse the array to find whether the array element exists with the current string. if it does not exist, the current string is output. if it exists, the key value of the array is output. Is the translation function. 1. determine whether the log has a corresponding Chinese character in the array (because the log is dead). 2. determine the day...

  'Rule buffer cleanup ', 'starting' => 'Start rule', 'Wait-> brk' => 'image status changed, from waiting to stopping status ', 'OK-> wait' => 'mirror status changed from OK to waiting status',); $ 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 ;}}}?>

What I want to do is to traverse the array to find whether the array element exists with the current string. if it does not exist, the current string is output. if it exists, the key value of the array is output.
Is the translation function.

1. determine whether the log has a corresponding Chinese character in the array (because some logs are dead ).
2. determine whether some strings in the log have the corresponding Chinese characters (some logs contain variable statements, so some strings must be matched and then translated ).
3. because the outer layer has a loop statement of the logs array, use break instead of exit.

Reply content:

  'Rule buffer cleanup ', 'starting' => 'Start rule', 'Wait-> brk' => 'image status changed, from waiting to stopping status ', 'OK-> wait' => 'mirror status changed from OK to waiting status',); $ 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 ;}}}?>

What I want to do is to traverse the array to find whether the array element exists with the current string. if it does not exist, the current string is output. if it exists, the key value of the array is output.
Is the translation function.

1. determine whether the log has a corresponding Chinese character in the array (because some logs are dead ).
2. determine whether some strings in the log have the corresponding Chinese characters (some logs contain variable statements, so some strings must be matched and then translated ).
3. because the outer layer has a loop statement of the logs array, use break instead of exit.

Why not leaveelseWhat about it?
You loop every word. the first loop isrep-cache during mirror is cleard,
Exist in$s?
Does not exist
Leaveelse?
Go
Not runningexit;?
Run
Continue?
Do not continue
Will the following words be checked?
Do not check

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.