0

我正在使用语言分类器的 API。我创建分类器,添加两个类,训练它们,然后发送一个要分类的字符串。分类调用的响应是一个数组:

$response = $uclassify->classify($bigString, $title);
print_r($response);

在响应上调用 print_r 会打印以下字符串(我已对其进行了标记以尝试理解它):

Array ( 
    [0] => Array ( 
        [id] => Classify12911363801322 
        [classification] => Array ( 
            [0] => Array ( 
                [class] => Cool [p] => **0.636574** 
            ) 
            [1] => Array ( 
                [class] => Uncool [p] => **0.363426** 
            ) 
        ) [text] => 
    )
)

我感兴趣的数组的唯一部分是数字(以粗体突出显示)。如何编写打印语句来提取这两个数字?

编辑:未修改的 print_r:

Array ( [0] => Array ( [id] => Classify12911363801322 [classify] => Array ( [0] => Array ( [class] => Cool [p] => 0.636574 ) [1] => Array ( [ class] => Uncool [p] => 0.363426 ) ) [text] => 海量文本字符串))

4

1 回答 1

1
$numbers = array();
foreach($response[0]['classification'] as $o){
    $numbers[] = $o['p'];
}
print_r($numbers);
于 2013-03-21T02:10:04.913 回答