Home  >  Article  >  Backend Development  >  数组取值,求解解决方案

数组取值,求解解决方案

WBOY
WBOYOriginal
2016-06-13 13:38:51859browse

数组取值,求解

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
      $uc = 33;
      $wc = getu_province();

      foreach ($wc as $k => $v) {
          $uv=$v['$uc'];
          $prolist = join('0010'.$uc);
      foreach ($uv as $s => $a) {
         if($a[0]=$prolist){
          $ucc = $a['$prolist'];}
               }
      }



$wc 类似于这样的东西Array ( [0] => Array ( [001011] => 北京 ) [1] => Array ( [001012] => 天津 ) [2] => Array ( [001013] => 河北 )....)

需要取001033的中文值,,,,怎么取? 好像上面写的不太对么>?

------解决方案--------------------
0010是固定的?没太看懂你的代码

PHP code

$testArray = array(array('001011' => '北京'), array('001012' => '天津'), array('001013' => '河北'));
//$wc = getu_province();
$uc = 12;
$find = '0010'.$uc;
foreach ($testArray as $value) {
    if (array_key_exists($find,$value)){
        echo '地区:' . $value[$find];
        break;
    }
}
<br><font color="#e78608">------解决方案--------------------</font><br>$uv=$v['$uc'];<br>和<br>$uv=$v["$uc"];<br>是不一样的。<br>
<br><font color="#e78608">------解决方案--------------------</font><br>$uc=1的话,<br>"$uc"就是"1",<br>'$uc'就是字符串"$uc"<br>因为双引号中,变量名称会被变量值所替代,然后才会发送给浏览器,而单引号就不会这样了。<br>
<br><font color="#e78608">------解决方案--------------------</font><br>
探讨

test OK !!

顺便求问$v[$uc] // $v['$uc'] // $v["$uc"];三者的差别!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn