繁体   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