PHP多維陣列KeyValue的使用
<?php $user["60"] = array("id" => "60", "num" => "56", "count" => "31"); $user["61"] = array("id" => "61", "num" => "22", "count" => "34"); $user["59"] = array("id" => "59", "num" => "32", "count" => "43"); $user["56"] = array("id" => "56", "num" => "41", "count" => "38"); $user["57"] = array("id" => "57", "num" => "39", "count" => "65"); $values = array_values($user);//返回陣列的所有值(非鍵名) $keys = array_keys($user);//返回包含陣列中所有鍵名的一個新陣列 $iskey=array_key_exists("57",$user);//檢查某個陣列中是否存在指定的鍵名,如果鍵名存在則返回 true,如果鍵名不存在則返回 false。 $iskey=array_key_exists(57,$user); //結果同上,不依賴型別,數字 57 與字串 "57" 是相同的。 $key =array_keys($keys,57) ;// 函式返回包含陣列中所有鍵名的一個新陣列。如果提供了第二個引數,則只返回鍵值為該值的鍵名。 $result[`status`] = 0; $result[`res`]=count($key); //$result[`res`] = $user; //-----------返回值是物件: //-----------{"status":0,"res":{"60":{"id":"60","num":"56","count":"31"},"61":{"id":"61","num":"22","count":"34"},"59":{"id":"59","num":"32","count":"43"},"56":{"id":"56","num":"41","count":"38"},"57":{"id":"57","num":"39","count":"65"}}} //$result[`res`] = $values; //-----------返回值是陣列: //-----------{"status":0,"res":[{"id":"60","num":"56","count":"31"},{"id":"61","num":"22","count":"34"},{"id":"59","num":"32","count":"43"},{"id":"56","num":"41","count":"38"},{"id":"57","num":"39","count":"65"}]} //$result[`res`] = $keys; //-----------返回值是key的一維陣列: //-----------{"status":0,"res":[60,61,59,56,57]} //sort($user);//按key排序之後,key被過濾掉 //$result[`res`] = $user; //-----------返回值是按key排序(不包括key)的多維陣列: //-----------{"status":0,"res":[{"id":"56","num":"41","count":"38"},{"id":"57","num":"39","count":"65"},{"id":"59","num":"32","count":"43"},{"id":"60","num":"56","count":"31"},{"id":"61","num":"22","count":"34"}]} echo json_encode($result); ?>
相關文章
- PHP中二維陣列與多維陣列PHP陣列
- PHP 多維陣列排序PHP陣列排序
- php 一維陣列變多維PHP陣列
- PHP多個多維陣列操作(一)PHP陣列
- php多維陣列去除空元素PHP陣列
- 多維陣列轉一維陣列(降維的多種方式)陣列
- PHP二維陣列轉一維陣列PHP陣列
- php多維陣列去除重複值的方法PHP陣列
- PHP指定欄位的多維陣列排序方法PHP陣列排序
- 簡單介紹Lua一維陣列與多維陣列的使用陣列
- 多維陣列陣列
- 一維多維陣列陣列
- PHP 多維陣列排序-按某個 key 的值PHP陣列排序
- C/C++ 二維陣列的理解(多維陣列)C++陣列
- [php]運用變數引用實現一維陣列轉多維樹狀陣列PHP變數陣列
- 多維陣列排序陣列排序
- php 二維陣列排序PHP陣列排序
- ***PHP陣列排序+php二維陣列排序方法(PHP比較器)PHP陣列排序
- Java陣列宣告建立和使用以及多維陣列、Arrays類、稀疏陣列Java陣列
- PHP學習筆記6:表示式&多維陣列PHP筆記陣列
- php中使用while遍歷二維陣列的方法PHPWhile陣列
- PHP一維陣列轉二維陣列正規表示式PHP陣列
- Multik——Kotlin的多維陣列Kotlin陣列
- JAVA多維陣列的遍歷Java陣列
- php如何遍歷多維的stdClassObject物件,php的轉換成陣列的函式只能轉換外面一叢陣列PHPObject物件陣列函式
- JavaScript 學習筆記 - 多維陣列變為一維陣列JavaScript筆記陣列
- scala語法 -多維陣列陣列
- 多維陣列扁平化陣列
- php二維陣列改鍵名的方法PHP陣列
- JavaSE 陣列:一維陣列&二維陣列Java陣列
- PHP把MYSQL重複ID二維陣列重組為三維陣列PHPMySql陣列
- 將一個多維陣列徹底的降維陣列
- NumPy之:ndarray多維陣列操作陣列
- 多維陣列拍平一層陣列
- c++筆記_多維陣列C++筆記陣列
- python多維陣列切片方法Python陣列
- PHP 陣列使用之道PHP陣列
- PHP二維關聯陣列的遍歷方式PHP陣列