我正在尝试解析从SmartyStreets(它是一个地址验证公司)返回的这些数据.
这是一个例子:
Array
(
[0] => stdClass Object
(
[input_index] => 0
[candidate_index] => 0
[delivery_line_1] => 3785 Las Vegas Blvd S
[last_line] => Las Vegas NV 89109-4333
[delivery_point_barcode] => 891094333992
[components] => stdClass Object
(
[primary_number] => 3785
[street_name] => Las Vegas
[street_postdirection] => S
[street_suffix] => Blvd
[city_name] => Las Vegas
[state_abbreviation] => NV
[zipcode] => 89109
[plus4_code] => 4333
[delivery_point] => 99
[delivery_point_check_digit] => 2
)
[metadata] => stdClass Object
(
[record_type] => H
[county_fips] => 32003 …Run Code Online (Sandbox Code Playgroud) 我试图从Vimeo Api中检索该字段的值,我已经尝试了这里提到的所有可能的解决方案.有人能告诉我如何分别从缩略图和网址对象中检索thumnail和url吗?
array(1) {
[0]=>
stdClass Object (
[allow_adds] => 1
[embed_privacy] => anywhere
[id] => 123456789
[is_hd] => 0
[is_transcoding] => 0
[license] => 0
[privacy] => anybody
[title] => Soap Opera
[description] =>
[upload_date] => 2014-02-20 03:03:50
[modified_date] => 2014-02-20 19:06:05
[number_of_plays] => 1
[number_of_likes] => 0
[number_of_comments] => 0
[width] => 600
[height] => 480
[duration] => 32
[owner] => stdClass Object (
[display_name] => blah
[id] => 12345678
[is_plus] => 0
[is_pro] => 1
[is_staff] => …Run Code Online (Sandbox Code Playgroud) 我有一个在MySQL中运行的查询,它返回一个结果作为stdClass对象,如下所示:
array(8){
[
0
]=>object(stdClass)#36(1){
[
"color"
]=>string(7)"#a0a0a0"
}[
1
]=>object(stdClass)#35(1){
[
"color"
]=>string(7)"#e0e0e0"
}[
2
]=>object(stdClass)#30(1){
[
"color"
]=>string(7)"#f0f0f0"
}[
3
]=>object(stdClass)#37(1){
[
"color"
]=>string(7)"#f0f0f1"
}[
4
]=>object(stdClass)#34(1){
[
"color"
]=>string(7)"#404040"
}[
5
]=>object(stdClass)#38(1){
[
"color"
]=>string(7)"#c0c0c0"
}[
6
]=>object(stdClass)#39(1){
[
"color"
]=>string(7)"#e06080"
}[
7
]=>object(stdClass)#40(1){
[
"color"
]=>string(7)"#e06082"
}
}
Run Code Online (Sandbox Code Playgroud)
我想得到颜色值.如何遍历此对象并将每个十六进制颜色存储在数组中?
我正在从数据库中提取记录,并且我有一个名为content_fr
" _fr基于站点语言动态创建"的文件.
从表中获取所有记录给了我当然的content_fr领域.我需要做的是手动分配后缀,case _fr如果我尝试连接$row->content.'_fr'我得到错误Notice: Undefined property: stdClass::$content,这是有道理的,因为$ content不存在,但$content_fr确实如此.使用标准数组我能够做到$row['content_fr'],并且工作正常,但现在使用stdClass我收到错误.
如何将其转换$row->content.'_fr'为一个字符串,以便php将其视为$row->content_fr?
我有数组的以下对象,并试图获取电子邮件的价值.如何才能做到这一点?
stdClass Object (
[status] => stdClass Object (
[info] => Unsubscribe List [code] => 200
)
[data] => Array (
[o1958147@rtrtr.com] => stdClass Object (
[date] => 2013-01-28 08:09:19
[origin] =>
)
[phil.houston@granherne.com] => stdClass Object (
[date] => 2013-01-28 08:35:59
[origin] =>
)
)
)
Run Code Online (Sandbox Code Playgroud)
目前我可以使用以下foreach访问日期值.
foreach ($fnret->data as $msg)
{
echo $msg->date; // shows 2013-01-28 08:35:59
}
Run Code Online (Sandbox Code Playgroud) 我可以使用匿名函数执行此操作
$func = function() {
return "Hello World";
};
var_dump($func());
Run Code Online (Sandbox Code Playgroud)
但是,我不能这样做
$namespace->func = function() {
return "Hello World";
};
var_dump($namespace->func());
Run Code Online (Sandbox Code Playgroud)
我会得到这个错误
调用未定义的方法stdClass
到目前为止我发现的解决方法是使用另一个变量
$temp = $namespace->func;
var_dump($temp());
Run Code Online (Sandbox Code Playgroud)
有没有办法可以在一行中完成?
鉴于这个 stdClass 结构......
[RecentAchievements] => stdClass Object
(
[1446] => stdClass Object
(
[3319] => stdClass Object
(
[ID] => 3319
[GameID] => 1446
[Title] => Hello World!
[Description] => Complete World 1-1
[Points] => 15
[BadgeName] => 03909
[IsAwarded] => 1
[DateAwarded] => 2013-10-20 19:35:46
)
Run Code Online (Sandbox Code Playgroud)
我需要检查 3319 里面的对象,比如“标题”,所以它就像:
$data->RecentAchievements->$gameid->ACHVIDHERE->Title;
Run Code Online (Sandbox Code Playgroud)
要获取 $gameid,它来自其他对象 (RecentlyPlayed),如下所示:
[RecentlyPlayed] => Array
(
[0] => stdClass Object
(
[GameID] => 1446
[ConsoleID] => 7
[ConsoleName] => NES
[Title] => Super Mario Bros
[LastPlayed] => 2013-10-20 …Run Code Online (Sandbox Code Playgroud) 虽然PHP中的类不需要明确扩展stdClass,但我想知道这样做是否存在某种最佳实践或好处.
stdClass在宣布上课时我应该延长吗?
有关参考,请参阅PHP中的什么是stdClass?和PHP:对象,转换为对象.
问题如下:
1)我在数据库中的几个表中有数百万行,因此使用Eloquent效率不高,因为我还有多个关系.在这种情况下,解决方案是编写自定义DB :: raw()选择和连接以有效地完成任务.如您所知,这将返回StdClass.
2)我有4-5个模型,我需要使用相当冗长的方法,因此最好的解决方案是为StdClass的每一行创建这些模型的实例,然后使用这些方法.
在OOP模式方面,是否存在将StdClass中的信息"移植"到模型中的已知"最佳实践"?你们怎么解决这个问题?我会接受任何建议,我准备甚至重组代码.
PS Laravel v4.2
我正在将数据添加到将通过 3rd 方 API 发送的 stdClass 对象,因此我为此对象的元素提供的名称实际上是由该外部服务定义的。
$insertArray = array();
$insertArray[0] = new stdclass();
$insertArray[0]->Name = $name;
$insertArray[0]->PhoneNumber = $phone;
Run Code Online (Sandbox Code Playgroud)
这一切都非常有效,直到我遇到一个名称无效的属性:
$insertArray[0]-> First.Name = $firstname;
所以这不是有效的 PHP 语法,有没有办法解决这个问题?