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
Related
I have two objects from an API I am trying to merge, one is a list of available subscription packages and one is a list of the current user's active subscription's and the corresponding status.
The first object looks like this:
This\Collection Object
(
[object] => list
[data] => Array
(
[0] => This\Product Object
(
[id] => 444
[name] => Test Plan 4
)
[1] => This\Product Object
(
[id] => 333
[name] => Test Plan 3
)
[2] => This\Product Object
(
[id] => 222
[name] => Test Plan 2
)
[3] => This\Product Object
(
[id] => 111
[name] => Test Plan 1
)
)
[has_more] =>
)
This second object looks like this:
Array
(
[0] => This\Subscription Object
(
[id] => sub_xxx
[current_period_end] => 1670307654
[current_period_start] => 1667715654
[plan] => This\Plan Object
(
[currency] => usd
[product] => 111
)
[start_date] => 1667715654
[status] => active
)
[1] => This\Subscription Object
(
[id] => sub_xxx
[current_period_end] => 1770507654
[current_period_start] => 1767715454
[plan] => This\Plan Object
(
[currency] => usd
[product] => 333
)
[start_date] => 1767715654
[status] => active
)
)
I want to combine the second object with the first object if subscription->plan->product matches product->id so it would look something like this:
This\Collection Object
(
[object] => list
[data] => Array
(
[0] => This\Product Object
(
[id] => 444
[name] => Test Plan 4
)
[1] => This\Product Object
(
[id] => 333
[name] => Test Plan 3
[subscription] => This\Subscription Object
(
[id] => sub_xxx
[current_period_end] => 1770507654
[current_period_start] => 1767715454
[plan] => This\Plan Object
(
[currency] => usd
[product] => 333
)
[start_date] => 1767715654
[status] => active
)
)
[2] => This\Product Object
(
[id] => 222
[name] => Test Plan 2
)
[3] => This\Product Object
(
[id] => 111
[name] => Test Plan 1
[subscription] => This\Subscription Object
(
[id] => sub_xxx
[current_period_end] => 1670307654
[current_period_start] => 1667715654
[plan] => This\Plan Object
(
[currency] => usd
[product] => 111
)
[start_date] => 1667715654
[status] => active
)
)
)
[has_more] =>
)
I know I can perform two foreach loops on each object and turn them into arrays with the revenant data I need and combine them that way, but I would rather merge them complete as objects.
How can I merge/combine these two in PHP?
Edit: This was my attempt at merging the two, but I am lost on how to actually make it work:
foreach($array1 as $product) {
foreach($array2 as $subscription) {
if ($subscription->plan->product == $product->id){
//how do I append to the object in the right place (where the 0 is)?
$array1->data[0]->subscription = $subscription->plan;
}
}
}
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']);
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'];
I am trying to create a tree inside a select box with an unlimited number of parent and children.
and my select box (html part) should be Access and I have given a diagram below.
I have a "categories" array which has two main arrays with an unlimited number of nodes (parent-child). The two main array names are [scope] => selectboxFirst and [scope] => selectboxsecond. There is a parentid which starts with 4000. I cannot hard code parentid in the code. The arrays come from a decoded json string.
I don't know how to loop through this array and show both arrays in a separate select box.
In the example array I have posted, there are two main arrays inside one array but they can also come in other arrays. I don't know how to display this in two select box as parent child.
All the [scope] => selectboxFirst categories will display in first select box and [scope] => selectboxsecond categories in second select box.
Array
(
[status] => Array
(
[message] => Good
[code] => 200
)
[categories] => Array
(
[0] => Array
(
[scope] => selectboxFirst
[categories] => Array
(
[0] => Array
(
[id] => 4001
[parentId] => 4000
[name] => Access
[children] => Array
(
[0] => Array
(
[id] => 4010
[parentId] => 4001
[name] => mine
[type] => Reference
)
[1] => Array
(
[id] => 4011
[parentId] => 4001
[name] => yours
[type] => Reference
)
)
[type] => Reference
)
[1] => Array
(
[id] => 4002
[parentId] => 4000
[name] => Communication
[children] => Array
(
[0] => Array
(
[id] => 4015
[parentId] => 4002
[name] => Physician
[children] => Array
(
[0] => Array
(
[id] => 4016
[parentId] => 4015
[name] => Helps blsys Understand
[type] => Reference
)
[1] => Array
(
[id] => 4017
[parentId] => 4015
[name] => Listens
[type] => Reference
)
)
[type] => Reference
)
[1] => Array
(
[id] => 4021
[parentId] => 4002
[name] => Clinical ps
[children] => Array
(
[0] => Array
(
[id] => 4022
[parentId] => 4021
[name] => yours ps/datasssss
[type] => Reference
)
)
[type] => Reference
)
[2] => Array
(
[id] => 4024
[parentId] => 4002
[name] => etc
[type] => Reference
)
)
[type] => Reference
)
[2] => Array
(
[id] => 4003
[parentId] => 4000
[name] => Office
[children] => Array
(
[0] => Array
(
[id] => 4026
[parentId] => 4003
[name] => Facilities/Environment
[children] => Array
(
[0] => Array
(
[id] => 4027
[parentId] => 4026
[name] => Noise
[type] => Reference
)
[1] => Array
(
[id] => 4028
[parentId] => 4026
[name] => Lighting
[type] => Reference
)
)
[type] => Reference
)
[1] => Array
(
[id] => 4032
[parentId] => 4003
[name] => Office ps
[children] => Array
(
[0] => Array
(
[id] => 4033
[parentId] => 4032
[name] => mine ps
[type] => Reference
)
)
[type] => Reference
)
[2] => Array
(
[id] => 4035
[parentId] => 4003
[name] => Billing
[type] => Reference
)
)
[type] => Reference
)
[3] => Array
(
[id] => 4004
[parentId] => 4000
[name] => Outgo
[children] => Array
(
[0] => Array
(
[id] => 4037
[parentId] => 4004
[name] => Diagnosis
[type] => Reference
)
[1] => Array
(
[id] => 4038
[parentId] => 4004
[name] => Quality of Procedure
[type] => Reference
)
)
[type] => Reference
)
[4] => Array
(
[id] => 4005
[parentId] => 4000
[name] => Loyalty
[children] => Array
(
[0] => Array
(
[id] => 4039
[parentId] => 4005
[name] => Likely to also
[type] => Reference
)
)
[type] => Reference
)
)
)
[1] => Array
(
[scope] => selectboxSecond
[categories] => Array
(
[0] => Array
(
[id] => 4251
[parentId] => 4250
[name] => Communication with datas
[children] => Array
(
[0] => Array
(
[id] => 4262
[parentId] => 4251
[name] => respect?
[type] => Reference
)
[1] => Array
(
[id] => 4263
[parentId] => 4251
[name] => you?
[type] => Reference
)
)
[type] => Reference
)
[1] => Array
(
[id] => 4252
[parentId] => 4250
[name] => Communication with Doctors
[children] => Array
(
[0] => Array
(
[id] => 4266
[parentId] => 4252
[name] => you with courtesy
[type] => Reference
)
)
[type] => Reference
)
[2] => Array
(
[id] => 4253
[parentId] => 4250
[name] => Responsiveness of data ps
[children] => Array
(
[0] => Array
(
[id] => 4269
[parentId] => 4253
[name] => During
[type] => Reference
)
[1] => Array
(
[id] => 4270
[parentId] => 4253
[name] => How
[type] => Reference
)
)
[type] => Reference
)
[3] => Array
(
[id] => 4254
[parentId] => 4250
[name] => Pain Management
[children] => Array
(
[0] => Array
(
[id] => 4271
[parentId] => 4254
[name] => During
[type] => Reference
)
)
[type] => Reference
)
[4] => Array
(
[id] => 4255
[parentId] => 4250
[name] => Communication about Medicines
[children] => Array
(
[0] => Array
(
[id] => 4274
[parentId] => 4255
[name] => During this data stay
[type] => Reference
)
[1] => Array
(
[id] => 4275
[parentId] => 4255
[name] => Before giving you
[type] => Reference
)
[2] => Array
(
[id] => 4276
[parentId] => 4255
[name] => Before giving you
[type] => Reference
)
)
[type] => Reference
)
[5] => Array
(
[id] => 4256
[parentId] => 4250
[name] => Discharge Information
[children] => Array
(
[0] => Array
(
[id] => 4277
[parentId] => 4256
[name] => During this data stay the data?
[type] => Reference
)
[1] => Array
(
[id] => 4278
[parentId] => 4256
[name] => After you left the data
[type] => Reference
)
[2] => Array
(
[id] => 4279
[parentId] => 4256
[name] => During this data stay
[type] => Reference
)
)
[type] => Reference
)
[6] => Array
(
[id] => 4257
[parentId] => 4250
[name] => Care Transition
[children] => Array
(
[0] => Array
(
[id] => 4280
[parentId] => 4257
[name] => During this data stay
[type] => Reference
)
)
[type] => Reference
)
[7] => Array
(
[id] => 4258
[parentId] => 4250
[name] => Cleanliness of data Environment
[children] => Array
(
[0] => Array
(
[id] => 4282
[parentId] => 4258
[name] => During this data?
[type] => Reference
)
)
[type] => Reference
)
[8] => Array
(
[id] => 4259
[parentId] => 4250
[name] => Quietness of data Environment
[children] => Array
(
[0] => Array
(
[id] => 4283
[parentId] => 4259
[name] => During this data?
[type] => Reference
)
)
[type] => Reference
)
[9] => Array
(
[id] => 4260
[parentId] => 4250
[name] => also the data
[children] => Array
(
[0] => Array
(
[id] => 4284
[parentId] => 4260
[name] => Would you?
[type] => Reference
)
)
[type] => Reference
)
[10] => Array
(
[id] => 4261
[parentId] => 4250
[name] => Overall Rating of data
[children] => Array
(
[0] => Array
(
[id] => 4285
[parentId] => 4261
[name] => Using any number
[type] => Reference
)
)
[type] => Reference
)
)
)
)
)
the output shoiuld be something like for eg: The ids should come inside selectbox along with option
Access
Electronics
--Keyboards
--Phones
----HTC DESIRE Z
----HTC ONE X
-------Camera
-------Battety
Food
--Fruits
----Apple
----Watermelon
--Vegetables
----Carrot
----Onion
**inside select box . for eg: <select><option value='4001'>Access</option></select>**
I have so far this much but it displays everything .Still not getting
$json = json_decode($string,TRUE);
//echo "<pre>";
//print_r($json);
recursive($json,$level=1);
function recursive($array, $level = 1){
foreach($array as $value){
//If $value is an array.
if(is_array($value)){
//We need to loop through it.
recursive($value, $level + 1);
} else{
//It is not an array, so print it out.
echo str_repeat("-", $level), $value, '<br>';
}
}
}
The following code will recurse through your data structure and create the list of options. I will leave the creation of the select tag to you, since it is very simple. I've used PHP_EOL to add line breaks after each option to make the HTML code easier to read.
foreach ($data['categories'] as $c) {
# scope is $c['scope']
echo "Starting " . $c['scope'] . PHP_EOL;
# calling the function on the categories data
recurse($c['categories']);
echo "Finished " . $c['scope'] . PHP_EOL;
}
function recurse($arr, $level = 0){
# we have a numerically-indexed array. go through each item:
foreach ($arr as $n) {
# print out the item ID and the item name
echo '<option value="' . $n['id'] . '">'
. str_repeat("-", $level)
. $n['name']
. '</option>'
. PHP_EOL;
# if item['children'] is set, we have a nested data structure, so
# call recurse on it.
if (isset($n['children'])) {
# we have children: RECURSE!!
recurse( $n['children'], $level+1);
}
}
}
Output:
Starting selectboxFirst
<option value="4001">Access</option>
<option value="4010">-mine</option>
<option value="4011">-yours</option>
<option value="4002">Communication</option>
<option value="4015">-Physician</option>
<option value="4016">--Helps blsys Understand</option>
<option value="4017">--Listens</option>
<option value="4021">-Clinical ps</option>
<option value="4022">--yours ps/datasssss</option>
<option value="4024">-etc</option>
<option value="4003">Office</option>
<option value="4026">-Facilities/Environment</option>
<option value="4027">--Noise</option>
(etc.)
You can substitute the appropriate code for "Starting selectboxFirst/selectboxSecond".
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.