簡體   English   中英

從輸出中獲取數據

[英]Grabbing data from output

我有一個試圖從中獲取數據的對象。 但是我似乎被困住了,任何幫助都會很棒,謝謝。

function att($prop, $what){
$reflObj = new ReflectionObject($prop);
$get = $reflObj->getProperty('attributes');
$get->setAccessible(true);
$info = $get->getValue($prop);

foreach($info as $inf){
$reflObj = new ReflectionObject($inf);

$title = $reflObj->getProperty('name');
$title->setAccessible(true);
$description = $title->getValue($inf);

var_dump("$description");

}
}

到目前為止的輸出示例:

string(11) "< Min Child"
string(9) "< Train S"
string(4) "<Pub"
string(5) "<Shop"
string(7) "Balcony"
string(4) "Bath"
string(9) "Bathrooms"
string(3) "BBQ"
string(5) "Beach"
string(9) "Bed Linen"
string(8) "Internet"
string(15) "Central Heating"
string(7) "Coast <"
string(3) "Cot"

基本上是希望從每個人那里獲取數據。

foreach($info as $inf){
$reflObj = new ReflectionObject($inf);

$title = $reflObj->getProperty('name');
$title->setAccessible(true);
$description = $title->getValue($inf);

var_dump("$description");

}

將此行更改為此:

$everything = array();
foreach($info as $inf){
    $reflObj = new ReflectionObject($inf);

    $title = $reflObj->getProperty('name');
    $title->setAccessible(true);
    $description = $title->getValue($inf);

    $everything[] = $description;

}
var_dump($everything);

$everything現在是一個數組,用於保存該輸出排序的數據。 如下訪問其值:

$everything[0]

將0替換為所需的索引。 例如, 3將屈服到第四個成員"<Shop"

您可以使用echo打印它們:

echo $everything[0];

提醒: var_dump()是用於輸出對象數據的調試工具。 永遠不要使用它來獲取輸入,因為它的實現可能因系統而異。 除非特別需要,否則應從已發布的應用程序中省略所有var_dump()代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM