在php中,有個多維陣列$b=array();,有個字串$a='[1][1]';有木有辦法從$b中取出$a位置上的值?

來源:互聯網
上載者:User
換句話說就是能不能用$a表示出$b[1][1]的形式。


回複討論(解決方案)

$a是不斷變化的啊 還有可能是$a='[1][1][1]';有木有大神知道啊

不行吧 要拆分$a成數組,迴圈。可變變數的形式應該不行


$a = array(array(1, 2, 3));
$b = '[0][2]';
$c = '$a' . $b;
eval('$d=' . $c . ';');
echo $d;
?>


$a = array(array(1, 2, 3));
$b = '[0][2]';
$c = '$a' . $b;
eval('$d=' . $c . ';');
echo $d;
?>

雖然eval被禁止使用,但也只能用這樣的方法了,感謝!

自己琢磨出來的

$b=array(array(1, 2, 3));
$a="[0][2]";
echo eval("return \$b$a;");
exit;
?>

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.