所以,我想通过它的属性来选择一个PHP对象,就像你如何通过$('.element[selector=false]')
有点东西在JS中选择一个HTML元素。选择一个类使用属性作为选择器 - PHP
我该怎么去选择类别Business
的对象名称为The Night's Watch
,而不知道它的变量名?
谢谢!
所以,我想通过它的属性来选择一个PHP对象,就像你如何通过$('.element[selector=false]')
有点东西在JS中选择一个HTML元素。选择一个类使用属性作为选择器 - PHP
我该怎么去选择类别Business
的对象名称为The Night's Watch
,而不知道它的变量名?
谢谢!
也不是那么困难,因为它似乎
// this will be array of all variables
$vars = get_defined_vars();
foreach(array_keys($vars) as $v)
if (gettype($$v) == 'object' and
get_class($$v) == 'Business' and // get_class returns class name
$$v->name == 'The Night's Watch') // test property
echo 'Variable you find is ' . $v;
为了找到字符串守夜..请做下面的代码的属性名称...
$string_to_find = "The Night's Watch";
//suppose $obj is the object of the class Business
foreach ($obj as $property => $value) {
if ($value == $string_to_find) {
// You found the string
echo $property;
echo $value;
}
}
您需要更具体的:这个“商业”对象存储在哪里?我想乍一看你的应用程序设计不合理:你应该能够选择对象并根据你选择的标准存储它们。 – Arcesilas
这取决于你的对象存储在哪里。你想从哪里搜索这个? – DaGardner
粘贴代码,然后我们可以帮助你。 – prava