使用列值分組2D數組數據,產生3D數組
P粉022140576
P粉022140576 2023-08-22 18:37:00
0
2
388
<p>我有一個多維數組,想要根據特定列中的值進行分組。 </p> <p>我想要依照<code>level</code>分組,但事先不知道level的值。所以,我不能像在<code>for</code>循環中說<code>while $i < 7</code>,因為我不知道<code>7</code>是level鍵的最大值,而且即使我知道也不確定我是否需要這樣做。 </p> <pre class="brush:php;toolbar:false;">[ ['cust' => 'XT8900', 'type' => 'standard', 'level' => 1], ['cust' => 'XT8944', 'type' => 'standard', 'level' => 1], ['cust' => 'XT8922', 'type' => 'premier', 'level' => 3], ['cust' => 'XT8816', 'type' => 'permier', 'level' => 3], ['cust' => 'XT7434', 'type' => 'standard', 'level' => 7], ]</pre> <p>期望的結果:</p> <pre class="brush:php;toolbar:false;">Array ( [1] => Array ( [0] => Array ( [cust] => XT8900 [type] => standard ) [1] => Array ( [cust] => XT8944 [type] => standard ) ) [3] => Array ( [2] => Array ( [cust] => XT8922 [type] => premier ) [3] => Array ( [cust] => XT8816 [type] => permier ) ) [7] => Array ( [4] => Array ( [cust] => XT7434 [type] => standard ) ) )</pre> <p><br /></p>
P粉022140576
P粉022140576

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!