php數組的格式輸出問題,請教大神

來源:互聯網
上載者:User
我有以下這樣一個表


請問,我要怎樣才能讓他根據 type類型和typeid來輸出下面這個數組格式?謝謝

Array(  [0] => array(            [0]=>            [1]=>婚慶服務            [2]=>機械裝置            [3]=>醫院醫學            [4]=>照明燈飾            [5]=>教育培訓            [6]=>化工塗料            [7]=>美容健身            [8]=>餐飲美食            [9]=>汽車服務            )[1] => array(            [0]=>            [1]=>常規            [2]=>兩列            [3]=>三列            [4]=>網格            ))


回複討論(解決方案)

查詢後讀取

while($row = mysql_fetch_assoc($rs)) {  $res[$row['type'][] = $row['typevalue'];}$res = array_values($row);

查詢後讀取

while($row = mysql_fetch_assoc($rs)) {  $res[$row['type'][] = $row['typevalue'];}$res = array_values($row);



xuzuning版主,我試了下頁面報錯哦。$res[$row['type'][] 這裡多了個]括弧,去掉了還是出錯。

排除了一下發現是這句出錯,$res = array_values($row); 這個是什麼原因呢?

噢,是漏了個括弧
$res[$row['type'] ][] = $row['typevalue'];

噢,是漏了個括弧
$res[$row['type'] ][] = $row['typevalue'];



xuzuning 版主,改成您最新的這個,還是會頁面出錯。提示是這句,出錯,不知道是什麼原因$res = array_values($row);

提示錯誤是Warning: array_values() expects parameter 1 to be array, boolean given in

指向的是這行 $res = array_values($row);

我的錯!
$res = array_values( $res);

噢,是漏了個括弧
$res[$row['type'] ][] = $row['typevalue'];


-----------------------------------
搞定了xuzuning版主,是$res = array_values($row); 這裡錯了,$row出來的不是數組所以會出錯,已經改好了,感謝您提供的思路。

我的錯!
$res = array_values( $res);


搞定了。(*^__^*) 嘻嘻……謝謝您
  • 聯繫我們

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