如何使用php从字符串数组和json返回特定元素

时间:2017-09-17 16:40:37

标签: php json

Array ( [0] => [[["15:30"," ","Alemania","Germany"," Bundesliga: ","Bayer Leverkusen - SC Freiburg"]]] [1] => [[["15:30"," ","Polonia","Poland"," Ekstraklasa: ","MKS Sandecja Nowy Sacz - Termalica Bruk-Bet Nieciecza"]]] [2] => [[["15:30"," ","Rusia","Russia"," Premier League: ","FC Rubin Kazan - FC Ural Yekaterinburg"]]] [3] => [[["16:00"," ","Albania","Albania"," Kategoria Superiore: ","KF Laci - Luftetari Gjirokaster"]]] [4] => [[["16:00"," ","Brasil","Brazil"," Brasileir\u00e3o Serie A: ","Avai SC - Atletico Mineiro MG"]]] 

如何使用php从这个对象获取数据,例如我需要花时间并将其保存在变量中

1 个答案:

答案 0 :(得分:1)

如果你需要时间

假设你有$ myArray

    $myArray =  Array ( [0] => [[["15:30"," ","Alemania","Germany"," Bundesliga: ","Bayer Leverkusen - SC Freiburg"]]] 
          [1] => [[["15:30"," ","Polonia","Poland"," Ekstraklasa: ","MKS Sandecja Nowy Sacz - Termalica Bruk-Bet Nieciecza"]]] 
          [2] => [[["15:30"," ","Rusia","Russia"," Premier League: ","FC Rubin Kazan - FC Ural Yekaterinburg"]]] 
          [3] => [[["16:00"," ","Albania","Albania"," Kategoria Superiore: ","KF Laci - Luftetari Gjirokaster"]]] 
          [4] => [[["16:00"," ","Brasil","Brazil"," Brasileir\u00e3o Serie A: ","Avai SC - Atletico Mineiro MG"]]] );

你可以使用

    foreach ($myArray as $key => $value) {
      $myTime[$key]=  $value[0][0][0] ;
    }
中的

=只有一个只有时间的数组