本文介绍了如何从PHP中的多维数组获取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我具有如下所示的多维数组,

i have multi dimensional array like below,

Array
(
    [14289] => Array
        (
            [0] => Ability:B,Itemname:Session #3: Tues June 28th - Fri July 8th (9-2:00PM)#1 only: 2pm
            [1] => Ability:B+,Itemname:Session #3: Tues June 28th - Fri July 8th (9-2:00PM)#1 only: 2pm
            [2] => Ability:B++,Itemname:Session #3: Tues June 28th - Fri July 8th (9-2:00PM)#1 only: 2pm
        )

    [14279] => Array
        (
            [0] => Ability:N/S,Itemname:Session #1: Tues May 31st - Fri June 10th (1-5:30PM)#1 only: 1pm
            [1] => Ability:N/S+,Itemname:Session #1: Tues May 31st - Fri June 10th (1-5:30PM)#1 only: 1pm
            [2] => Ability:N/S++,Itemname:Session #1: Tues May 31st - Fri June 10th (1-5:30PM)#1 only: 1pm
        )

    [14288] => Array
        (
            [0] => Ability:N/S,Itemname:Session #3: Tues June 28th - Fri July 8th (9-2:00PM)#1 only: 1:30pm
        )

    [14291] => Array
        (
            [0] => Ability:N/S+,Itemname:Session #4: Tues July 12th - Fri July 22nd (9-2:00PM)#1 only: 1pm
        )

    [14284] => Array
        (
            [0] => Ability:N/S++,Itemname:Session #2: Tues June 14th - Fri June 24th (9-2:00PM)#1 only: 1:30pm
        )

)

我需要从中获取值

我该怎么做?。

推荐答案

假定 $ array 包含您的数据,下面的代码将完成此操作。

Assuming $array contains your data, the following code will do it.

$result = array();
foreach($array as $a){
    foreach($a as $l){
        list($ab, $it) = explode(",", $l, 2);
        $ab = substr($ab, strlen("Ability:"));
        $it = substr($it, strlen("Itemname:"));
        $result[] = array(
            'Ability' => $ab,
            'Itemname' => $it
        );
    }
}

这篇关于如何从PHP中的多维数组获取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 23:16