[英]Grabbing data from output
I have an object I'm trying to get data from. 我有一个试图从中获取数据的对象。 But I seem to be stuck, any help would be great, Thanks. 但是我似乎被困住了,任何帮助都会很棒,谢谢。
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");
}
}
Example of output so far: 到目前为止的输出示例:
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"
Basically looking to grab the data from each. 基本上是希望从每个人那里获取数据。
foreach($info as $inf){
$reflObj = new ReflectionObject($inf);
$title = $reflObj->getProperty('name');
$title->setAccessible(true);
$description = $title->getValue($inf);
var_dump("$description");
}
Change this line into this: 将此行更改为此:
$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
is now an array that holds data ordered by that output. $everything
现在是一个数组,用于保存该输出排序的数据。 Access its values like this: 如下访问其值:
$everything[0]
Replace 0 with index of what you need. 将0替换为所需的索引。 For instance, 3
will yield to 4th member which is "<Shop"
. 例如, 3
将屈服到第四个成员"<Shop"
。
You can print them with echo
: 您可以使用echo
打印它们:
echo $everything[0];
Reminder: var_dump()
is a debug tool for outputting object data. 提醒: var_dump()
是用于输出对象数据的调试工具。 It should never be used to grab input since its implementation may vary among systems. 永远不要使用它来获取输入,因为它的实现可能因系统而异。 All var_dump()
code should be omitted from the released application unless it is particularly necessary. 除非特别需要,否则应从已发布的应用程序中省略所有var_dump()
代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.