【发布时间】:2017-11-13 05:40:51
【问题描述】:
我收到了一个 PHP 数组,格式如下:
[0] => Array
(
[mainCatID] => 2
[mainCatCode] => cat2
[mainCatDesc] => Acupuncture
[mainCatAddedDate] => 2016-10-12 10:22:49
[mainCatStatus] => active
)
[1] => Array
(
[mainCatID] => 3
[mainCatCode] => cat3
[mainCatDesc] => Medical
[mainCatAddedDate] => 2016-10-12 10:22:49
[mainCatStatus] => active
)
[2] => Array
(
[mainCatID] => 4
[mainCatCode] => cat4
[mainCatDesc] => Aids & Hiv
[mainCatAddedDate] => 2016-10-12 10:22:49
[mainCatStatus] => active
)
[3] => Array
(
[mainCatID] => 1
[mainCatCode] => cat1
[mainCatDesc] => Brains
[mainCatAddedDate] => 2016-10-12 10:22:49
[mainCatStatus] => active
)
我想要实现的是根据 [mainCatDesc] 第一个字母将数组拆分为不同的字母“块”。所以预计结果如下:
一个
针灸 艾滋病和艾滋病毒
B
大脑
M
医疗
提前感谢您的帮助!干杯!
- 已编辑 *
目前我只有
$con = open_connection();
$allMainCatArray = getAllMainCat($con);
close_connection($con);
echo "<pre>";
print_r($allMainCatArray);
echo "</pre>";
【问题讨论】:
-
你需要提供代码,你试过什么?
-
啊啊码的意思?
-
这段代码是什么?这段代码和你的问题有什么关系?
-
到目前为止,我只有一个 print_r() 来输出我返回的数组。我尝试使用数组块,但函数需要的参数似乎不适合我的需要
-
你试过简单的循环吗?还有一些数组推送?
标签: php arrays multidimensional-array split alphabetical