Вложенный массив PHP в ответ на Google Speech API, как извлечь элемент?

0

Я получаю следующий ответ от google speech API, к которому обращается PHP. Как получить доступ к элементам "транскрипта" из этого вложенного массива:

Array ( 
    [0] => Array ( 
        [alternative] => Array ( 
            [0] => Array ( 
                [transcript] => it been really fun doing these surveys there super easy they usually take about 5 minutes and at the same time you get to talk about your feelings on different brands of products do you need anything from toothpaste to beer they've been super easy you just may come with your phone and I've always been paid incredibly quickly if not that day then the next so it a really great way to make a little extra cash without a whole lot of effort and have some fun doing it 
            ) 
            [1] => Array ( 
                [transcript] => it been really fun doing these surveys their super easy they usually take about 5 minutes and at the same time you get to talk about your feelings on different brands of products do you need anything from toothpaste to beer they've been super easy you just may come with your phone and I've always been paid incredibly quickly if not that day then the next so it a really great way to make a little extra cash without a whole lot of effort and have some fun doing it 
            ) 
            [2] => Array ( 
                [transcript] => it been really fun doing these surveys they're super easy they usually take about 5 minutes and at the same time you get to talk about your feelings on different brands of products do you need anything from toothpaste to beer they've been super easy you just may come with your phone and I've always been paid incredibly quickly if not that day then the next so it a really great way to make a little extra cash without a whole lot of effort and have some fun doing it 
            ) 
            [3] => Array ( 
                [transcript] => it been really fun doing any surveys their super easy they usually take about 5 minutes and at the same time you get to talk about your feelings on different brands of products do you need anything from toothpaste to beer they've been super easy you just may come with your phone and I've always been paid incredibly quickly if not that day then the next so it a really great way to make a little extra cash without a whole lot of effort and have some fun doing it 
            ) 
            [4] => Array ( 
                [transcript] => it been really fun doing any surveys they're super easy they usually take about 5 minutes and at the same time you get to talk about your feelings on different brands of products do you need anything from toothpaste to beer they've been super easy you just may come with your phone and I've always been paid incredibly quickly if not that day then the next so it a really great way to make a little extra cash without a whole lot of effort and have some fun doing it 
            ) 
        ) 
        [final] => 1 
    ) 
)

Теги:
arrays
multidimensional-array

1 ответ

1
Лучший ответ

Для доступа к одному транскрипту: $response[0]['alternative'][0]['transcript']

переименовать все:

foreach ($responses as $response) {
  foreach ($response['alternative'] as $alternative) {
    $transcript = $alternative['transcript'];
  }
}

Ещё вопросы

Сообщество Overcoder
Наверх
Меню