how to retrieve variable from object - php

I want to retrieve $se_module value from my object. How can I get that? I can easily get others by $object->Owner->name. I've tried $object->{$se_module}, but got error as undefined variable.
stdClass Object
(
[Owner] => stdClass Object
(
[name] => Merv Henry
[id] => 2880896000003943001
)
[Modified_Time] => 2019-01-09T21:25:05-05:00
[$attachments] =>
[Created_Time] => 2019-01-09T21:25:05-05:00
[Parent_Id] => stdClass Object
(
[name] =>
[id] => 2880896000011553097
)
[$editable] => 1
[$se_module] => Deals
[Modified_By] => stdClass Object
(
[name] => Merv Henry
[id] => 2880896000003943001
)
[$size] =>
[$voice_note] =>
[id] => 2880896000011676081
[Created_By] => stdClass Object
(
[name] => Merv Henry
[id] => 2880896000003943001
)
[Note_Title] =>
[Note_Content] => This unit needs 1# DA97-12540K & 1# DA97-13718C
Quote is needed
)

you cane make it as array then you can get it
$data = (array)$se_module;
then can get data like this
$data['Modified_Time'];

Related

php parse array in object detail

I got stuck on parsing array in my php object
stdClass Object
(
[result] => stdClass Object
(
[details] => Array
(
[0] => stdClass Object
(
[account] =>
[address] => add1
[category] => receive
[amount] => 1100
[label] =>
[vout] => 1
)
[1] => stdClass Object
(
[account] =>
[address] => add2
[category] => receive
[amount] => 11600
[label] =>
[vout] => 2
)
[2] => stdClass Object
(
[account] =>
[address] => add3
[category] => receive
[amount] => 1000
[label] =>
[vout] => 4
)
)
)
)
So how I can fetch all details indexes 0,1,2 etc
So, you could just iterate over details as below:
foreach($your_variable->result->details as $current_detail){
echo $current_detail->account;
// other code here
}
Your data is object if you converto to array u can simply do it
$array=json_decode(json_encode($data),true);
print_r($array);
If just one details key
$array=json_decode(json_encode($data),true)
print_r($array['result']['details']);

Softalyer API - calling getBlockDeviceTemplateGroups

we have a problem in using getBlockDeviceTemplateGroups(): It returns always "blockDevicesDiskSpaceTotal" values as zero.
PHP CODE:
$mask = "mask[name, blockDevicesDiskSpaceTotal, storageRepository[billingItem[associatedBillingItem]], createDate, datacenter, datacenters,id,parentId]";
$client = SoftLayer_SoapClient::getClient('SoftLayer_Account', null, $apiUsername, $apiKey);
$client->setObjectMask($mask);
//Retrieve private template group objects (parent and children) and the shared template group objects (parent only) for an account.
$templates = $client->getBlockDeviceTemplateGroups();
OUTPUT of print_r($templates):
Array
(
[0] => stdClass Object
(
[createDate] => 2016-02-29T17:42:04+01:00
[id] => 966271
[name] => 20160229-JMeter-Master.bluereply.it
[parentId] =>
[blockDevicesDiskSpaceTotal] => 0
[datacenters] => Array
(
[0] => stdClass Object
(
[id] => 814994
[longName] => Amsterdam 3
[name] => ams03
[statusId] => 2
)
[1] => stdClass Object
(
[id] => 815394
[longName] => Milan 1
[name] => mil01
[statusId] => 2
)
)
)
[1] => stdClass Object
(
[createDate] => 2016-02-29T17:31:10+01:00
[id] => 966247
[name] => 20160229-JMeter-Slave.bluereply.it
[parentId] =>
[blockDevicesDiskSpaceTotal] => 0
[datacenters] => Array
(
[0] => stdClass Object
(
[id] => 815394
[longName] => Milan 1
[name] => mil01
[statusId] => 2
)
[1] => stdClass Object
(
[id] => 814994
[longName] => Amsterdam 3
[name] => ams03
[statusId] => 2
)
[2] => stdClass Object
(
[id] => 449500
[longName] => Paris 1
[name] => par01
[statusId] => 2
)
)
and so on...
Thanks in advance
try using this objectMask:
mask[name, blockDevicesDiskSpaceTotal, storageRepository[billingItem[associatedBillingItem]],children[blockDevicesDiskSpaceTotal,datacenter], createDate, datacenter, datacenters,id,parentId]
the problem is that the images templates have a container which stores the real images templates for each datacenter, currently you are getting the "blockDevicesDiskSpaceTotal" of the container which is empty, you need to get that information form the container's children.
Regards

Accessing a value from a returned object [duplicate]

This question already has answers here:
Able to see a variable in print_r()'s output, but not sure how to access it in code
(9 answers)
Closed 8 years ago.
Here is a print_r() of my returned object:
Array
(
[0] => stdClass Object
(
[list_id] => 547009977
[list_name] => Master List
[list_type] => email
[member_data] => Array
(
[0] => stdClass Object
(
[name] => work_phone
[value] =>
)
[1] => stdClass Object
(
[name] => city
[value] =>
)
[2] => stdClass Object
(
[name] => restricted_since
[value] =>
)
[3] => stdClass Object
(
[name] => unsub_campaign_id
[value] =>
)
[4] => stdClass Object
(
[name] => title
[value] =>
)
[5] => stdClass Object
(
[name] => comments
[value] =>
)
[6] => stdClass Object
(
[name] => company_name
[value] =>
)
[7] => stdClass Object
(
[name] => Info
[value] =>
)
[8] => stdClass Object
(
[name] => address_hash
[value] =>
)
[9] => stdClass Object
(
[name] => hash
[value] => 2054ee9827
)
[10] => stdClass Object
(
[name] => country
[value] =>
)
[11] => stdClass Object
(
[name] => id
[value] => 45
)
[12] => stdClass Object
(
[name] => gender
[value] =>
)
[13] => stdClass Object
(
[name] => postalcode
[value] =>
)
[14] => stdClass Object
(
[name] => address_1
[value] =>
)
[15] => stdClass Object
(
[name] => create_date
[value] => 2013-07-15T15:31:35+00:00
)
[16] => stdClass Object
(
[name] => optin_status_last_updated
[value] => 2013-07-15T15:31:35+00:00
)
[17] => stdClass Object
(
[name] => Purchased
[value] =>
)
[18] => stdClass Object
(
[name] => marital_status
[value] =>
)
[19] => stdClass Object
(
[name] => optin_status
[value] => null
)
[20] => stdClass Object
(
[name] => last_updated
[value] => 2013-07-15T15:31:35+00:00
)
[21] => stdClass Object
(
[name] => address_2
[value] =>
)
[22] => stdClass Object
(
[name] => home_phone
[value] =>
)
[23] => stdClass Object
(
[name] => fax
[value] =>
)
[24] => stdClass Object
(
[name] => first_name
[value] => CoregTest
)
[25] => stdClass Object
(
[name] => bounce_campaign_id
[value] =>
)
[26] => stdClass Object
(
[name] => Page
[value] =>
)
[27] => stdClass Object
(
[name] => is_cass_certified
[value] => 0
)
[28] => stdClass Object
(
[name] => last_name
[value] =>
)
[29] => stdClass Object
(
[name] => restricted
[value] => 0
)
[30] => stdClass Object
(
[name] => mobile_phone
[value] =>
)
[31] => stdClass Object
(
[name] => email_address
[value] => coregtest#chrisjallen.com
)
[32] => stdClass Object
(
[name] => ip_address
[value] =>
)
[33] => stdClass Object
(
[name] => state
[value] =>
)
)
)
)
All I want to do is access the list_id in my php code. If I put it into a $result var:
$result = $vr->searchListMembers( array(
'session_id' => $sid,
'field_name' => 'email_address',
'field_value' => $email,
'max_records' => 1
) );
I've tried
$result->list_id
and
$result[0]['list_id']
This is seemingly obvious but I'm missing something here.
Try:
$list_id = $result[0]->list_id;
$list_id = $result['list_id'];
however, list_id isn't in your code. So perhaps you meant session_id. Regardless, the syntax is:
array['key']
ChromePHP doesn't seem like a very useful tool. This is because PHP and JavaScript have different data types/data structures, so a JavaScript console output won't tell you about how the object looks in PHP.
In JavaScript, objects and arrays can be accessed using []. In PHP, objects and arrays are accessed with different syntax. PHP arrays use [] and objects use ->.
If you want to debug PHP, I suggest you use var_dump (or print_r), this will show you if you have an array or an object. A JavaScript console will always show object, and is not very useful.
In your case, you need to access your element via:
$result[0]->list_id
Omitting the fact that list_I'd isn't there it really depends on the return type of the searchListMember method you are using. If the returned var is an object you have to use ->list_id if its an array then it really about the structure but it should go like $result['list_id']
Try this!
print $result[0]->list_id;
If you do :
$result = $vr->searchListMembers( array(
'session_id' => $sid,
'field_name' => 'email_address',
'field_value' => $email,
'max_records' => 1
) );
$result is an Array.
So first you have to access the first element: $result[0]
Then, it is a stdClass object so you can access its properties with the -> operator:
$result[0]->list_id

PHP - Objects and Arrays - How to access an stdClass object "name" "value" pair inside an array?

I would like to know how to return a value of an object with a name value pair that's inside an array. I've been trying all sorts of methods and frankly I realized I may be way over my head on this. I'd like some assistance trying to get the AirportsInformation_DataExtension value inside the property array.
stdClass Object
(
[OverallStatus] => OK
[RequestID] => 19e41b46-df68-47ba-8858-d728f3a92036
[Results] => stdClass Object
(
[PartnerKey] =>
[ObjectID] =>
[Type] => DataExtensionObject
[Properties] => stdClass Object
(
[Property] => Array
(
[0] => stdClass Object
(
[Name] => CampaignName
[Value] => 20130107_FlightDealsHotelPricePoints
)
[1] => stdClass Object
(
[Name] => StartDate
[Value] => 1/7/2013 12:00:00 AM
)
[2] => stdClass Object
(
[Name] => EndDate
[Value] => 1/15/2013 5:59:59 AM
)
[3] => stdClass Object
(
[Name] => CampaignType
[Value] => FlightDeals
)
[4] => stdClass Object
(
[Name] => LandingPage_ExpireDate
[Value] => 1/15/2013 5:59:59 AM
)
[5] => stdClass Object
(
[Name] => LandingPage_AutoRedirectOnExpire
[Value] => True
)
[6] => stdClass Object
(
[Name] => LandingPage_ExpireTargetURL
[Value] => test
)
[7] => stdClass Object
(
[Name] => BookByDate
[Value] => 1/22/2013 12:00:00 AM
)
[8] => stdClass Object
(
[Name] => TravelStartDate
[Value] =>
)
[9] => stdClass Object
(
[Name] => TravelEndDate
[Value] =>
)
[10] => stdClass Object
(
[Name] => FlightDeals_DataExtension
[Value] => 20130107_DestinationFlightDeals
)
[11] => stdClass Object
(
[Name] => FlightDeals_SortOrder_DataExtension
[Value] => FlightDeals_DestinationSortOrder
)
[12] => stdClass Object
(
[Name] => HotelDeals_DataExtension
[Value] => 20130107_FlightDealsHotelPricePoints
)
[13] => stdClass Object
(
[Name] => HotelDeals_All_DataExtension
[Value] => 20130107_HotelPackageDeals_ALL
)
[14] => stdClass Object
(
[Name] => HotelInformation_DataExtension
[Value] => EmailHotelInformation
)
[15] => stdClass Object
(
[Name] => AirportsInformation_DataExtension
[Value] => Airports
)
[16] => stdClass Object
(
[Name] => RoutesInformation_DataExtension
[Value] => Routes
)
[17] => stdClass Object
(
[Name] => DFP_DataExtension
[Value] => ET_DestinationIframeSrc
)
[18] => stdClass Object
(
[Name] => DeepLinkConnectorURL
[Value] => http://www.somewebsite/BookingConnector.html?mode=run
)
[19] => stdClass Object
(
[Name] => DefaultDestinationScenery
[Value] => LAS
)
[20] => stdClass Object
(
[Name] => DefaultHomeAirportCode
[Value] =>
)
[21] => stdClass Object
(
[Name] => FailSafeHomeAiportCode
[Value] =>
)
[22] => stdClass Object
(
[Name] => DFP_Campaign_Banner
[Value] => True
)
[23] => stdClass Object
(
[Name] => EmailID
[Value] => 44388
)
)
)
)
)
Using a foreach loop I was able to print out all lines with name/value sets
foreach ($results->Results->Properties->Property as $CurrentProp){
print('<br>');
print('Name: '.$CurrentProp->Name. ' Value: '.$CurrentProp->Value.'<br>');
};
Sadly I can't get passed that. I just need to retrieve the value. Thanks in advance.
In order to get the value, you could loop over them and test for the name matching AirportsInformation_DataExtension:
foreach ($results->Results->Properties->Property as $CurrentProp){
if($CurrentProp->Name == 'AirportsInformation_DataExtension')
{
echo 'The value is: ' . $CurrentProp->Value;
}
}
If you would need to be able to get all the values based on their name, it could be useful to turn it in to an associative array, like this
$results->Results->Properties->PropertyArray = array();
foreach($results->Results->Properties->Property as $arrCurrentProperty) {
$results->Results->Properties->PropertyArray[$arrCurrentProperty->Name] = $arrCurrentProperty->Value;
};
Then you can get the values later by indexing them directly, i.e.
echo 'The value is: ' . $results->Results->Properties->PropertyArray['AirportsInformation_DataExtension'];
Use the above solution by MrCode or, simply just use $results->Results->Properties->Property[15]->Value if the index of AirportsInformation_DataExtension is always 15. Since an array is an ordered list, it is very probably that the index does not change unless some of the items are removed/added from the array/
foreach ($results->Results->Properties->Property as $CurrentProp){
$tempArr[$CurrentProp->Name] = $CurrentProp->Value;
}
echo $tempArr['AirportsInformation_DataExtension'];
By this you can access any other key of that object.

How would I read this array ("stdClass Object")

I am using the Quizlet API 2.0, and I am pretty new to this
How do I read a value(s) from something like this:
stdClass Object ( [id] => 102269 [name] => Learn Spanish with Cats! [set_count] => 3 [user_count] => 10 [created_date] => 1308035691 [is_public] => 1 [has_password] => [has_access] => 1 [has_discussion] => 1 [member_add_sets] => 1 [description] => This set is exclusively for Spanish flashcard sets with relevant cat images as the set definitions. [sets] => Array ( [0] => stdClass Object ( [id] => 6081999 [url] => http://quizlet.com/6081999/lesson-4-with-catsdogs-flash-cards/ [title] => Lesson 4 (with cats+dogs) [created_by] => wsvincent [term_count] => 33 [created_date] => 1311984796 [modified_date] => 1312490710 [has_images] => 1 [subjects] => Array ( [0] => spanish cats dogs ) [visibility] => public [editable] => groups [has_access] => 1 ) [1] => stdClass Object ( [id] => 5855751 [url] => http://quizlet.com/5855751/paso-a-paso-book-1-chapter-4-flash-cards/ [title] => Paso a Paso Book 1 Chapter 4 [created_by] => catdawg426 [term_count] => 30 [created_date] => 1307761267 [modified_date] => 1307819129 [has_images] => 1 [subjects] => Array ( [0] => spanish ) [visibility] => public [editable] => only_me [has_access] => 1 ) [2] => stdClass Object ( [id] => 5873819 [url] => http://quizlet.com/5873819/los-gatos-de-viaje-flash-cards/ [title] => Los Gatos de Viaje! [created_by] => tiffreja [term_count] => 21 [created_date] => 1307996657 [modified_date] => 1307996796 [has_images] => 1 [subjects] => Array ( [0] => spanish [1] => language [2] => foreign ) [visibility] => public [editable] => only_me [has_access] => 1 ) ) [members] => Array ( [0] => stdClass Object ( [username] => philfreo [role] => creator [email_notification] => 1 ) [1] => stdClass Object ( [username] => milkncookies [role] => member [email_notification] => 1 ) [2] => stdClass Object ( [username] => Icypaw [role] => member [email_notification] => ) [3] => stdClass Object ( [username] => luckycat10 [role] => member [email_notification] => ) [4] => stdClass Object ( [username] => jeffchan [role] => member [email_notification] => ) [5] => stdClass Object ( [username] => catchdave [role] => member [email_notification] => 1 ) [6] => stdClass Object ( [username] => tiffreja [role] => member [email_notification] => 1 ) [7] => stdClass Object ( [username] => catdawg426 [role] => member [email_notification] => 1 ) [8] => stdClass Object ( [username] => ihaque [role] => member [email_notification] => 1 ) [9] => stdClass Object ( [username] => jalenack [role] => member [email_notification] => 1 ) ) )
For instance, if I want to get the name of that first set, "Learn Spanish with Cats", how do I echo it via variable?
It already converts the JSON to an array I think:
$data = json_decode($json);
Your object is not an array, but rather, well, an Object. So use the -> operator to access its properties:
echo $data->name;
It contains a property which itself is an array of additional objects. For example, to get the URL of id 6081999, you would do:
echo $data->sets[0]->url;
// http://quizlet.com/6081999/lesson-4-with-catsdogs-flash-cards/
Here is a simple solution to convert a stdClass Object in array in php with get_object_vars
Look at : https://www.php.net/manual/en/function.get-object-vars.php
Example :
dump($array);
$var = get_object_vars($array);
dump($var);
Or replace dump() function by print_r()
Use function key
eg echo key($array)
I have looked something before, when you use the json_decode()
$data = json_decode();
U can send some parameters, the first of them is "$json", it will be the json string
{"1":"first","2":"second"}
But that json decode with one parameter return an Object and the default value of the second parameter is "false". If you want that back in array you only need to use the second parameter and send "true".
$data =json_decode($json,true);
And you can recibe it like an array. :)
In case you got stdClass Object in the array, for example
$user = $result1->fetch_object() then set $user into a variable
$val = $user->user_id (make sure user_id is your database column name, its the column name). You will get a single value in $val that comes from database.

Categories