sabre:遍历电话属性无法提供预期的结果

时间:2019-05-30 13:12:42

标签: php vcard sabre sabredav

一个可能很简单的问题-但我很傻:

sabre/vobject usage instruction之后,我将循环TEL-property以获取数字及其类型。

BEGIN:VCARD
TEL;TYPE=HOME,PREF:+15551234560
TEL;TYPE=HOME,FAX:+15551234569
TEL;TYPE=WORK:+155523456789
END:VCARD
foreach ($vCard->TEL as $number) {
    echo (string)$number . ': ' . $vCard->TEL['TYPE'] . PHP_EOL;
}

代替

+15551234560: HOME,PREF
+15551234569: HOME,FAX
+155523456789: WORK

我收到:

+15551234560: HOME,PREF
+15551234569: HOME,PREF
+155523456789: HOME,PREF

2 个答案:

答案 0 :(得分:0)

我找到的解决方法是:

foreach ($vCard->TEL as $key => $number) {
    echo (string)$number . ': ' . $vCard->TEL[$key]->parameters['TYPE'] . PHP_EOL;
}

答案 1 :(得分:-1)

foreach ($vCard->TEL as $number) {
    echo (string)$number . ': ' . $number['TYPE'] . PHP_EOL;
}