我$this->db->get_where()用来从codeigniter中的数据库中获取数据.它返回后我使用print_r()
它看起来像一堆stdClass object.任何人如何访问此数组中的值.
Array ( [0] =>
stdClass Object (
[id] => 1
[password321] => qwerty
[email123] => example@gmail.com
[username123] => xyz
)
)
Run Code Online (Sandbox Code Playgroud) 我用它来检查一个对象是否有属性,
function objectHasProperty($input){
return (is_object($input) && (count(get_object_vars($input)) > 0)) ? true : false;
}
Run Code Online (Sandbox Code Playgroud)
但后来我想进一步检查以确保所有属性都有值,例如,
stdClass Object
(
[package] =>
[structure] =>
[app] =>
[style] =>
[js] =>
)
Run Code Online (Sandbox Code Playgroud)
然后,false如果所有属性都有空值,我想返回.可能吗?任何提示和想法?
我已经尝试了其他帖子的解释我无法让它工作,因为我总是得到以下警告:警告:get_object_vars()期望参数1是对象,数组给出...
stdclass对象数组如下所示:
Array
(
[0] => stdClass Object
(
[pares] => 4
[moda] => 9
)
[1] => stdClass Object
(
[pares] => 3
[moda] => 8
)
[2] => stdClass Object
(
[pares] => 2
[moda] => 8
)
[3] => stdClass Object
(
[pares] => 5
[moda] => 4
)
[4] => stdClass Object
(
[pares] => 1
[moda] => 1
)
[5] => stdClass Object
(
[pares] => 6
[moda] => 1
)
)
Run Code Online (Sandbox Code Playgroud)
我尝试分别访问值 - modas和pares及其数字 …
我在PHP中有以下示例数据:
[{"id": 2088996538},{},{"id": 2077495673}]
Run Code Online (Sandbox Code Playgroud)
我怎么能最终得到
[{"id": 2088996538},{"id": 2077495673}]
Run Code Online (Sandbox Code Playgroud)
我尝试了几件事,比如
unset($activities[1]);
Run Code Online (Sandbox Code Playgroud)
但后来我结束了
{"0":{"id":2088996538},"2":{"id":2077495673}}
Run Code Online (Sandbox Code Playgroud)
它看起来很简单,但无法搞清楚.
最终目标是清理一些strava api输出,删除我不使用的所有内容.
编辑:
$activities = json_decode('[{"id": 2088996538},{},{"id": 2077495673}]');
unset($activities[1]);
$activities = array_values($activities);
echo json_encode($activities);
Run Code Online (Sandbox Code Playgroud)
这实际上有效,我怎么能错过它.用更大的数据集来试试吧.谢谢!
我是一名中级PHP程序员,但我正在努力使用Google AJAX API的输出.我有以下转换为stdClass
stdClass Object (
[responseData] => stdClass Object (
[results] => Array (
[0] => stdClass Object (
[GsearchResultClass] => GwebSearch
[unescapedUrl] => http://www.1860-1960.com/shoes.html
[url] => http://www.1860-1960.com/shoes.html
[visibleUrl] => www.1860-1960.com
[cacheUrl] => http://www.google.com/search?q=cache:4bB2OicXg5EJ:www.1860-1960.com
[title] => Beautiful Antique Shoes and Boots, Vintage Fashions [titleNoFormatting] => Beautiful Antique Shoes and Boots, Vintage Fashions
[content] => Victorian White Kid Child's Straight Sole Shoes c1850. Victorian Child's Needlepoint Bunny ... Lovely Vintage Shoes. Antique shoes or antique boots. ...
)
[1] => …Run Code Online (Sandbox Code Playgroud) 场景:
$x = json_decode( $x );
foreach ( $x as $item )
{
$info[] = $item; //ERROR
}
Run Code Online (Sandbox Code Playgroud)
我正在循环使用数据馈送来获取数据.我想在循环中将项添加到stdClass对象.我该怎么办?我对stdobj不太熟悉.
是否可以从PHP stdClass检查属性?我有一些模型作为stdClass生成.在使用它们时,我想检查我正在调用的属性是否存在于某种Core类中.我注意到stdClass忽略了__get ...
如果stdClass中的属性存在于对象中,它们如何检查?
在PHP中执行stdClass时我们可以这样做:
// Create new stdClass Object
$init = new stdClass;
// Add some test data
$init->foo = "Test data";
$init->bar = new stdClass;
$init->bar->baaz = "Testing";
$init->bar->fooz = new stdClass;
$init->bar->fooz->baz = "Testing again";
$init->foox = "Just test";
Run Code Online (Sandbox Code Playgroud)
有没有其他替代方法可以使它看起来更像我们可以使用JavaScript?
谢谢.
我正在使用 Laravel 5 并且我有一个必须更新数据库的简单编辑页面。当我尝试运行它时,出现错误
UserController.php 第 47 行中的 FatalErrorException:调用未定义的方法 stdClass::update()
控制器 :
public function userUpdate()
{
if(Input::get('send')) {
$arr = [
'email' => Input::get('email')
];
DB::table(Config::get('users_table'))->find(Input::get('userId'))->update(['is_active' => TRUE]);
return redirect()->route('users');
}
}
Run Code Online (Sandbox Code Playgroud)
数据库架构:
id bigserial NOT NULL,
username text,
email text,
permission integer NOT NULL,
is_staff boolean NOT NULL DEFAULT false,
is_active boolean NOT NULL DEFAULT false,
updated_at timestamp without time zone,
created_at timestamp without time zone,
remember_token text
Run Code Online (Sandbox Code Playgroud)
路线 :
Route::post('/user/update', [
'as' => 'userUpdate', 'uses' => 'UserController@userUpdate'
]); …Run Code Online (Sandbox Code Playgroud) 当我做这样的事情时,我正在运行PHP7.0.9:
$s = json_decode('{"1": "xxx"}');//decode json to stdClass
$a = (array)$s;//cast to array
die(var_dump($a, $a['1'], $a[1], count($a)));
Run Code Online (Sandbox Code Playgroud)
我得到这个结果:
array (size=1)
'1' => string 'xxx' (length=3) //<-- key 1 exists
null // $a['1'] yields null
null // $a[1] doesn't work either
int 1 // count shows there is 1 element in the array
Run Code Online (Sandbox Code Playgroud)
我期待这个结果:
array (size=1)
'1' => string 'xxx' (length=3)
string 'xxx' (length=3) // $a['1'] should work
null
int 1
Run Code Online (Sandbox Code Playgroud)
我的问题:为什么我不能访问$a['1'],即使两个count和一个var_dump数组告诉我这个密钥存在?这是PHP中的错误,还是某种功能?