How to understand this piece of code

Source: Internet
Author: User
public static function read ($file) {
Str_replace (', ', ', ', $file);
$tmp = Explode (', ', $file);
foreach ($tmp as $v) {
$tmp _file = Base_path. ' /language/'. Lang_type. DS. $v. ' PHP ';
if (file_exists ($tmp _file)) {
Require ($tmp _file);
if (!empty ($lang) && Is_array ($lang)) {
Self:: $language _content = Array_merge (self:: $language _content, $lang);
}
Unset ($lang);
}
}
return true;
}
The writing in the above Code str_replace (', ', ', ', $file), what is the purpose of it, does it not feel the effect of it, is it to prevent what?


Reply to discussion (solution)

Here is an extra sentence, because the result of str_replace substitution is not copied to $file

This sentence is to replace the Chinese comma with a comma, but this is not directly written, to assign value to $file
public static function read ($file) {
$file = Str_replace (', ', ', ', $file); Change the Chinese comma to English
$tmp = Explode (', ', $file);//use commas to divide the names into groups
foreach ($tmp as $v) {//loop array
$tmp _file = Base_path. ' /language/'. Lang_type. DS. $v. php;//Find a file based on the key value of the array
if (file_exists ($tmp _file)) {//If the file exists
Require ($tmp _file);//Return file
if (!empty ($lang) && Is_array ($lang)) {//If $lang is not empty and is a number of arrays
Self:: $language _content = Array_merge (self:: $language _content, $lang);
}
Unset ($lang);//Delete $lang
}
}
Return true;//Returns True
}

The full-width "," replaced by ",", conjecture may be used for example, when the tag, prompting the user more than one label can be separated, but some users input the time to write the full-width, so the full-width of the replacement.

This sentence is to replace the Chinese comma with a comma, but this is not directly written, to assign value to $file
public static function read ($file) {
$file = Str_replace (', ', ', ', $file); Change the Chinese comma to English
$tmp = Explode (', ', $file);//use commas to divide the names into groups
foreach ($tmp as $v) {//loop array
$tmp _file = Base_path. ' /language/'. Lang_type. DS. $v. php;//Find a file based on the key value of the array
if (file_exists ($tmp _file)) {//If the file exists
Require ($tmp _file);//Return file
if (!empty ($lang) && Is_array ($lang)) {//If $lang is not empty and is a number of arrays
Self:: $language _content = Array_merge (self:: $language _content, $lang);
}
Unset ($lang);//Delete $lang
}
}
Return true;//Returns True
}


Again, the final result of this method is to return true;
My question is, what's the use of this function, because it finally returns a true, does it mean anything?

Who says it's useless, does it not have the following statement, which merges the static variable $language _content of the class one at a time when the condition is met.
if (!empty ($lang) && Is_array ($lang)) {
Self:: $language _content = Array_merge (self:: $language _content, $lang);
}

Return true is only the return value when the condition is not satisfied.

Who says it's useless, does it not have the following statement, which merges the static variable $language _content of the class one at a time when the condition is met.
if (!empty ($lang) && Is_array ($lang)) {
Self:: $language _content = Array_merge (self:: $language _content, $lang);
}

Return true is only the return value when the condition is not satisfied.


It should be the return value when the condition is met.

Oh, that's wrong. Whether or not into if will be executed return true, in fact, return true here is not much use, you just look at my red that paragraph is enough.

The main point is require ($tmp _file);
Bulk loader Program Files

  • 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.