數組取值,求解解決方案

來源:互聯網
上載者:User
數組取值,求解
PHP code
      $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;    }}
------解決方案--------------------
$uv=$v['$uc'];

$uv=$v["$uc"];
是不一樣的。

------解決方案--------------------
$uc=1的話,
"$uc"就是"1",
'$uc'就是字串"$uc"
因為雙引號中,變數名稱會被變數值所替代,然後才會發送給瀏覽器,而單引號就不會這樣了。

------解決方案--------------------
探討

test OK !!

順便求問$v[$uc] // $v['$uc'] // $v["$uc"];三者的差別!
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.