I am facing strange issue in looping json object using php. Here is the format of my data
stdClass Object
(
[userform] => Array
(
[0] => stdClass Object
(
[id] => 69
[product] => testuser
)
[1] => stdClass Object
(
[id] => 70
[product] => testuser
)
[2] => stdClass Object
(
[id] => 71
[product] => testuser
)
[3] => stdClass Object
(
[id] => 72
[product] => testuser
)
[4] => stdClass Object
(
[id] => 73
[product] => testuser
)
[5] => stdClass Object
(
[id] => 74
[product] => testuser
)
[6] => stdClass Object
(
[id] => 75
[product] => testuser
)
[7] => stdClass Object
(
[id] => 76
[product] => testuser
)
[8] => stdClass Object
(
[id] => 77
[product] => testuser
)
[9] => stdClass Object
(
[id] => 78
[product] => testuser
)
[10] => stdClass Object
(
[id] => 79
[product] => testuser
)
[11] => stdClass Object
(
[id] => 80
[product] => testuser
)
[12] => stdClass Object
(
[id] => 81
[product] => testuser
)
[13] => stdClass Object
(
[id] => 82
[product] => testuser
)
[14] => stdClass Object
(
[id] => 83
[product] => testuser
)
[15] => stdClass Object
(
[id] => 84
[product] => testuser
)
[16] => stdClass Object
(
[id] => 85
[product] => testuser
)
[17] => stdClass Object
(
[id] => 86
[product] => testuser
)
[18] => stdClass Object
(
[id] => 87
[product] => testuser
)
[19] => stdClass Object
(
[id] => 88
[product] => testuser
)
[20] => stdClass Object
(
[id] => 89
[product] => testuser
)
)
)
But this loop throws following error.
Trying to get property of non-object in
Please let me know how to read the product property value from the above format
Thanks all
That foreach should be on $data->userform , not just $data
foreach($data->userform as $key=>$row){
if(isset($row->product)){
print_r($key);
print_r($row->product);
}else{
//product property is not set
}
}
Related
This Question is continuation of My first question
So I have an array
Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => stdClass Object
(
[id] => 79
[name] => shelin
[status] => 0
)
[1] => stdClass Object
(
[id] => 80
[name] => shanu
[status] => 2
)
[2] => stdClass Object
(
[id] => 81
[name] => linto
[status] => 2
)
[3] => stdClass Object
(
[id] => 82
[name] => joseph
[status] => 0
)
)
)
I sort this array
$sorted = $collection->sortByDesc('status');
my view
return view('voyager::users.viewusersAppraisals')->with('values', $sorted);
Now, I got array like
Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[2] => stdClass Object
(
[id] => 81
[name] => linto
[status] => 2
)
[1] => stdClass Object
(
[id] => 80
[name] => shanu
[status] => 2
)
[0] => stdClass Object
(
[id] => 79
[name] => shelin
[status] => 0
)
[3] => stdClass Object
(
[id] => 82
[name] => joseph
[status] => 0
)
)
)
and my foreach loop
#foreach($values as $data)<?php
?>
<tr>
<td>{{$data->name}}</td>
</tr>
#endforeach
I expect output like so
linto
shanu
shelin
joseph
But I get output like so
joseph
linto
shanu
shelin
Any help would be appreciated. Thanks in advance.
It must be your variable be getting overwritten somewhere in the code which you have not mentioned.
Also please dd($sorted) your result after executing the eloquent query to see whether you are getting data from db in right format as per your need.
I have a string which i am spitting using explode functionality. Code Snippet is shown below
$string = "2017167637/ 43/ 42/ 38/ 46/ 41/ 40/ 39";
$tags = (explode("/",$string));
print_r($tags);
foreach ($tags as $key)
$invoicedata[] = (object)$key;
echo '<pre>'; print_r($invoicedata); exit;
The Output what i am getting right now is
Array ( [0] => 2017167637 [1] => 43 [2] => 42 [3] => 38 [4] => 46 [5] => 41 [6] => 40 [7] => 39 )
Array
(
[0] => stdClass Object
(
[scalar] => 2017167637
)
[1] => stdClass Object
(
[scalar] => 43
)
[2] => stdClass Object
(
[scalar] => 42
)
[3] => stdClass Object
(
[scalar] => 38
)
[4] => stdClass Object
(
[scalar] => 46
)
[5] => stdClass Object
(
[scalar] => 41
)
[6] => stdClass Object
(
[scalar] => 40
)
[7] => stdClass Object
(
[scalar] => 39
)
But the actual output what i need is in place of [scalar] i need [invoice]. How to do it? Any help appreciated.
Actual output what i need is shown below
Array ( [0] => 2017167637 [1] => 43 [2] => 42 [3] => 38 [4] => 46 [5] => 41 [6] => 40 [7] => 39 )
Array
(
[0] => stdClass Object
(
[invoice] => 2017167637
)
[1] => stdClass Object
(
[invoice] => 43
)
[2] => stdClass Object
(
[invoice] => 42
)
[3] => stdClass Object
(
[invoice] => 38
)
[4] => stdClass Object
(
[invoice] => 46
)
[5] => stdClass Object
(
[invoice] => 41
)
[6] => stdClass Object
(
[invoice] => 40
)
[7] => stdClass Object
(
[invoice] => 39
)
)
I tried with adding $invoice['invoice'] but it did not worked so how to get the desired output any help appreciated.
Here is working code. Try this.
$string = "2017167637/ 43/ 42/ 38/ 46/ 41/ 40/ 39";
$tags = (explode("/",$string));
print_r($tags);
foreach ($tags as $key=>$value)
{
$invoicedata[$key] = new stdClass();
$invoicedata[$key]->invoice = $value;
}
echo '<pre>'; print_r($invoicedata); exit;
I am trying to foreach loop in laravel.Here is my print_r result of jobseekers.
Illuminate\Support\Collection Object (
[items:protected] => Array (
[0] => stdClass Object ( [myid] => 37 [max(call_back_date)] => 2018-12-12 )
[1] => stdClass Object ( [myid] => 60 [max(call_back_date)] => 2017-12-12 )
[2] => stdClass Object ( [myid] => 61 [max(call_back_date)] => 2017-11-30 )
[3] => stdClass Object ( [myid] => 73 [max(call_back_date)] => 2017-11-29 )
[4] => stdClass Object ( [myid] => 62 [max(call_back_date)] => 2017-11-28 )
[5] => stdClass Object ( [myid] => 63 [max(call_back_date)] => 2017-11-22 )
[6] => stdClass Object ( [myid] => 64 [max(call_back_date)] => 2017-11-15 )
[7] => stdClass Object ( [myid] => 66 [max(call_back_date)] => 2017-11-15 )
[8] => stdClass Object ( [myid] => 65 [max(call_back_date)] => 2017-11-10 )
[9] => stdClass Object ( [myid] => 54 [max(call_back_date)] => 2017-10-24 )
[10] => stdClass Object ( [myid] => 53 [max(call_back_date)] => 2017-09-30 )
[11] => stdClass Object ( [myid] => 48 [max(call_back_date)] => 2017-09-20 )
[12] => stdClass Object ( [myid] => 46 [max(call_back_date)] => 2017-08-26 )
[13] => stdClass Object ( [myid] => 58 [max(call_back_date)] => 2017-12-12 )
[14] => stdClass Object ( [myid] => 70 [max(call_back_date)] => 2017-11-29 )
[15] => stdClass Object ( [myid] => 47 [max(call_back_date)] => 2017-08-20 )
[16] => stdClass Object ( [myid] => 44 [max(call_back_date)] => 2017-08-18 )
[17] => stdClass Object ( [myid] => 72 [max(call_back_date)] => 2018-02-17 )
[18] => stdClass Object ( [myid] => 55 [max(call_back_date)] => 2000-12-12 )
[19] => stdClass Object ( [myid] => 49 [max(call_back_date)] => )
[20] => stdClass Object ( [myid] => 50 [max(call_back_date)] => )
[21] => stdClass Object ( [myid] => 74 [max(call_back_date)] => )
[22] => stdClass Object ( [myid] => 32 [max(call_back_date)] => )
)
)
and i tried like this
foreach ($jobseekers as $value) {
echo $value->myid;
}
it shows me only the first item. like "37", i expect many items. like "37,60,61 etc...".
i think you need to do more one loop to iterate the data.
update
try one of this
foreach($jobseekers ->items as value){}
or this
foreach ($jobseekers as $value) {
foreach ($value as $item) {}
}
I want to count the number of likes (and comments) on a Facebook post. But when there's more than 25 likes on a post, the results are paginated like that:
stdClass Object ( [data] => Array ( [0] => stdClass Object ( [id] => 802020049912534 [name] => Sagar Lama ) [1] => stdClass Object ( [id] => 590020061101130 [name] => Sheguey Squaad ) [2] => stdClass Object ( [id] => 696207733846316 [name] => Ossama Barcalona ) [3] => stdClass Object ( [id] => 1901218896769448 [name] => Gab Alviola ) [4] => stdClass Object ( [id] => 407069606150738 [name] => Thongloy Thichanon ) [5] => stdClass Object ( [id] => 947084195347741 [name] => Thomas Vujić ) [6] => stdClass Object ( [id] => 1614068872196230 [name] => เพื่à¸à¸™à¸à¸¹à¹€à¸ˆà¹‡à¸š ชีวิตมึงจบ ) [7] => stdClass Object ( [id] => 1431328280529413 [name] => Ali-Bilal Dernek ) [8] => stdClass Object ( [id] => 855095404568872 [name] => Henry Feng ) [9] => stdClass Object ( [id] => 937460179628960 [name] => Rex Lu ) [10] => stdClass Object ( [id] => 1627484497506023 [name] => Röbërt GärÄïâ ) [11] => stdClass Object ( [id] => 971640236220159 [name] => Reyjoel Jimeno ) [12] => stdClass Object ( [id] => 1644471585776456 [name] => Og Catwalk ) [13] => stdClass Object ( [id] => 1652037021731712 [name] => Rafik Benchibane ) [14] => stdClass Object ( [id] => 499561140196412 [name] => Lizy Smith ) [15] => stdClass Object ( [id] => 10207169299621544 [name] => Ngai Lam ) [16] => stdClass Object ( [id] => 505507699598850 [name] => Ëlloï Gonzalez Sanchez ) [17] => stdClass Object ( [id] => 802078276575586 [name] => Armando Sanchez ) [18] => stdClass Object ( [id] => 10205977306769395 [name] => Fredy Santizo ) [19] => stdClass Object ( [id] => 811409772291367 [name] => Malik Davis ) [20] => stdClass Object ( [id] => 842376069172521 [name] => Isak Renee Martinez ) [21] => stdClass Object ( [id] => 915675738506394 [name] => Kimora Stephens Davis ) [22] => stdClass Object ( [id] => 916531748393520 [name] => Isabel Averill ) [23] => stdClass Object ( [id] => 941049645918044 [name] => Mathias Tenezaca Mendez ) [24] => stdClass Object ( [id] => 1452189318420627 [name] => Andrew Hernandez ) ) [paging] => stdClass Object ( [cursors] => stdClass Object ( [after] => MTQ1MjE4OTMxODQyMDYyNw== [before] => ODAyMDIwMDQ5OTEyNTM0 ) [next] => https://graph.facebook.com/v2.3/15087023444_10153196470723445/likes?access_token=xxxxxxxxxxxxxxxxxxx&limit=25&after=MTQ1MjE4OTMxODQyMDYyNw%3D%3D ) )
How can I count likes and comments on a given post without asking the Facebook API too much. I'm using the PHP SDK
You can either use paging to go through all Likes, or you can use the summary parameter to get a total count:
/post-id?fields=likes.summary(true)
Part of the response:
"summary": {
"total_count": 393,
"can_like": true,
"has_liked": false
}
Been searching for a solution for my problem. Seams meny has the same q as me, but still haven't got a solution for my problem.
I have a stdClass Object that needs to be printed out in a foreach or somlike like that.
Here is a cut of the result i get with a "print_r($result)".
stdClass Object
(
[ServiceGroup] => Array
(
[0] => stdClass Object
(
[Service] => Array
(
[0] => stdClass Object
(
[_] => 3D-modulering
[count] => 71
)
[1] => stdClass Object
(
[_] => CAD
[count] => 81
)
[2] => stdClass Object
(
[_] => Databasutveckling
[count] => 118
)
[3] => stdClass Object
(
[_] => Datainmatare
[count] => 6
)
[4] => stdClass Object
(
[_] => Driftsteknik
[count] => 87
)
[5] => stdClass Object
(
[_] => IT-konsult
[count] => 39
)
[6] => stdClass Object
(
[_] => IT-tekniker
[count] => 223
)
[7] => stdClass Object
(
[_] => Mjuk- och hårdvarutestning
[count] => 150
)
[8] => stdClass Object
(
[_] => Nätverksteknik
[count] => 142
)
[9] => stdClass Object
(
[_] => Produkttestare
[count] => 171
)
[10] => stdClass Object
(
[_] => Programmerare
[count] => 146
)
[11] => stdClass Object
(
[_] => Projektledning
[count] => 156
)
[12] => stdClass Object
(
[_] => Serviceteknik
[count] => 157
)
[13] => stdClass Object
(
[_] => Support
[count] => 360
)
[14] => stdClass Object
(
[_] => Systemadministration
[count] => 145
)
[15] => stdClass Object
(
[_] => Systemutveckling
[count] => 110
)
[16] => stdClass Object
(
[_] => Webbdesign
[count] => 246
)
[17] => stdClass Object
(
[_] => Webbutveckling
[count] => 135
)
[18] => stdClass Object
(
[_] => webmaster
[count] => 103
)
)
[name] => Data/IT
)
[1] => stdClass Object
(
[Service] => Array
(
[0] => stdClass Object
(
[_] => Affärsanalys
[count] => 192
)
[1] => stdClass Object
(
[_] => Aktuarie
[count] => 20
)
I don't know exactly what you want, but can easily foreach through objects just like arrays. This example shows that.
foreach($result->ServiceGroup as $value){
foreach($value->Service as $obj){
echo $obj->_;
echo $obj->count;
}
echo $value->name;
}