How to get the all the pricing value from the json array - php

How to get all the pricing values from the JSON array? I need to split two segments tld's (com,in,in.net,etc...) and the corresponding tld pricing value I tried to get the values from the array but com, in etc those are key values.
My JSON Array
Array
(
[result] => success
[pricing] => Array
(
[com] => Array
(
[categories] => Array
(
[0] => gTLD
[1] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 637.70
)
[transfer] => Array
(
[1] => 637.70
)
[renew] => Array
(
[1] => 637.70
)
)
[in] => Array
(
[categories] => Array
(
[0] => ccTLD
[1] => Geography
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 1014.67
)
[transfer] => Array
(
[1] => 1014.67
)
[renew] => Array
(
[1] => 1014.67
)
)
[info] => Array
(
[categories] => Array
(
[0] => gTLD
[1] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 200.00
)
[transfer] => Array
(
[1] => 200.00
)
[renew] => Array
(
[1] => 200.00
)
)
[net] => Array
(
[categories] => Array
(
[0] => gTLD
[1] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 829.76
)
[transfer] => Array
(
[1] => 829.76
)
[renew] => Array
(
[1] => 829.76
)
)
[biz] => Array
(
[categories] => Array
(
[0] => gTLD
[1] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 878.33
)
[transfer] => Array
(
[1] => 878.33
)
[renew] => Array
(
[1] => 878.33
)
)
[org] => Array
(
[categories] => Array
(
[0] => gTLD
[1] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 939.45
)
[transfer] => Array
(
[1] => 939.45
)
[renew] => Array
(
[1] => 939.45
)
)
[asia] => Array
(
[categories] => Array
(
[0] => gTLD
[1] => ccTLD
[2] => Geography
[3] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 1527.88
)
[transfer] => Array
(
[1] => 1527.88
)
[renew] => Array
(
[1] => 1527.88
)
)
[co.uk] => Array
(
[categories] => Array
(
[0] => ccTLD
[1] => Geography
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 602.53
)
[transfer] => Array
(
[1] => 602.53
)
[renew] => Array
(
[1] => 602.53
)
)
[in.net] => Array
(
[categories] => Array
(
[0] => Other
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 100.00
)
[transfer] => Array
(
[1] => 100.00
)
[renew] => Array
(
[1] => 100.00
)
)
[uk] => Array
(
[categories] => Array
(
[0] => ccTLD
[1] => Geographic
[2] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 200.00
)
[transfer] => Array
(
[1] => 300.00
)
[renew] => Array
(
[1] => 400.00
)
)
)
)
How to split the array and get the transfer values from the above JSON array?

If I don't misunderstood your question then this is what you need with simple foreach() loop to get tlds with their corresponding prices
$expected = [];
foreach($result['pricing'] as $tld=>$array){
// this is the register value, you can change it for transfer or renew if you wish
$expected[$tld] = $array['register'][1];
}
print_r($expected);

Related

How to access the values of this API return

Could you please help me? I need to know how to access the values of this response from an API call using PHP.
Array ( [queryIds] => Array ( [0] => lHLLapn7EH ) [timedOutRealtimeData] => [realtimeDataMissing] => [cacheFreshness] => FRESH [prunedResult] => [novaCost] => 0 [novaRequestDuration] => 19 [wasCached] => 1 [minSampleRate] => 1 [timeComputed] => 1558794556710 [novaRuntime] => 199 [hitChunkGroupByLimit] => [throttleTime] => 0 [data] => Array ( [series] => Array ( [0] => Array ( [0] => Array ( [setId] => [value] => 843 ) ) [1] => Array ( [0] => Array ( [setId] => [value] => 22 ) ) ) [seriesLabels] => Array ( [0] => Array ( [0] => 0 [1] => C5241; GB ) [1] => Array ( [0] => 0 [1] => C9999; GB ) ) [seriesMeta] => Array ( [0] => Array ( [eventGroupBys] => Array ( [0] => C5241 [1] => GB ) [segmentIndex] => 0 [eventIndex] => 0 [eventGroupBy] => C5241; GB ) [1] => Array ( [eventGroupBys] => Array ( [0] => C9999 [1] => GB ) [segmentIndex] => 0 [eventIndex] => 0 [eventGroupBy] => C9999; GB ) ) [seriesCollapsed] => Array ( [0] => Array ( [0] => Array ( [setId] => [value] => 843 ) ) [1] => Array ( [0] => Array ( [setId] => [value] => 22 ) ) ) [xValues] => Array ( [0] => 2019-05-25 ) ) [partialMergedAndNewUserInformation] => [transformationIds] => Array ( [0] => 2696 ) [backend] => novaV2 )
You can access them using
Array ( [0] => C9999 [1] => GB ) -> $arr['data']['seriesMeta'][0]['eventGroupBys']
Array ( [setId] => [value] => 20) -> $arr['data']['seriesMeta'][0][0]

looping through multidimensional array from post and save to mysql

This is the array which i get from post
Array
(
[data] => Array
(
[Invoice] => Array
(
[itemNo] => Array
(
[0] => rtgrg
[1] => 4t4t
[2] => ththt
[3] => thth
)
[itemName] => Array
(
[0] => rtgrt
[1] => 4t5t5
[2] => hthtyh
[3] => gnghnn
)
[itemDiscription] => Array
(
[0] => 5tr5t
[1] => t45t4
[2] => tyhthtyh
[3] => gnghnh
)
[price] => Array
(
[0] => 2
[1] => 10
[2] => 9
[3] => 12
)
[itemQuantity] => Array
(
[0] => 2
[1] => 12
[2] => 9
[3] => 9
)
[itemDiscount] => Array
(
[0] => 11
[1] => 0.14
[2] => 0.13
[3] => 0.1
)
[itemTotal] => Array
(
[0] => 333333
[1] => 34535
[2] => 55555555555555
[3] => 666666666
)
[itemStartDate] => Array
(
[0] =>
[1] =>
[2] =>
[3] => 2016-06-17
)
[itemEndDate] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
)
[itemCustomcol] => Array
(
[0] => 4t4t4
[1] => t5trgr
[2] => htht
[3] => gngh
)
[itemCustomcol2] => Array
(
[0] => t4t4t
[1] => rtgtr
[2] => thth
[3] => gng
)
[itemttax2] => Array
(
[0] => tax1
)
[itemttax3] => Array
(
[0] => tax1
)
[itemttax4] => Array
(
[0] => tax1
)
[itemtCsTax] => Array
(
[0] => gngn
)
[itemtCsTaxPer] => Array
(
[0] => 0.1
)
[itemtDiscount] => Array
(
[0] => 0.18
)
[itemtInvReceived] => Array
(
[0] => gngn
)
[itemtInvToReturn] => Array
(
[0] => gngng
)
[itemInvDue] => Array
(
[0] => nghnghng
)
[itemInvComment] => Array
(
[0] => hngnhg
)
)
)
There is a separate table for dynamic input like itemName, itemDiscription to itemCustomcol2 and another table for itemttax2 to itemInvComment .
I tried foreach loop for multiple element array but this doent work for me as it returns a string. one of them is shown below
$capture_field_vals ="";
foreach($_POST["data"]["Invoice"]["itemNo"] as $key => $text_field){
$capture_field_vals .= $text_field .", ";
}
echo $capture_field_vals;
What i want is collect all element[0] and then insert it in a row mysql and then another element another row and so on.
Is there any reason you can't use the following format?
Array
(
[data] => Array
(
[Invoice] => Array
(
[0] => Array
(
[itemNo] => number
[itemName] => name
[itemDescription] => desc
[price] => 0.00
),
[1] => Array
(
[itemNo] => number
[itemName] => name
[itemDescription] => desc
[price] => 0.00
),...
with this method you can loop through retrieving all details of each item in the invoice?
If I have misunderstood your problem, I apologise

retrieving data from a php object

I am trying to access data inside a php object. I am confused about what the exact stynax is. Here is the output of the object:
stdClass Object ( [vid] => 10 [uid] => 1 [title] => Beachhead Don [log] =>
[status] => 1 [comment] => 1 [promote] => 0 [sticky] => 0 [ds_switch] => [nid] =>
10 [type] => product [language] => und [created] => 1357668665 [changed] => 1358198386
[tnid] => 0 [translate] => 0 [revision_timestamp] => 1358198386 [revision_uid] => 1
[model] => B 3000 [list_price] => 0.00000 [cost] => 0.00000 [sell_price] => 1.00000
[weight] => 0 [weight_units] => lb [length] => 0 [width] => 0 [height] => 0
[length_units] => in [pkg_qty] => 1 [default_qty] => 1 [unique_hash] =>
2eec0fcc8483f3a3541870fb24223296 [ordering] => 0 [shippable] => 0 [price] => 1.00000
[body] => Array ( [und] => Array ( [0] => Array ( [value] => Description info
))))))))))))))))))))))))))))))))))))))0 [summary] => [format] => filtered_html
[safe_value] =>Description info ))))))))))))))))))))))))))))))))))))))0[safe_summary]
=> ) ) ) [uc_product_image] => Array ( [und] => Array ( [0] => Array ( [fid] => 11
[alt] => [title] => [width] => 90 [height] => 120 [uid] => 1 [filename] =>
beachhead_don.jpg [uri] => public://beachhead_don.jpg [filemime] => image/jpeg
[filesize] => 14342 [status] => 1 [timestamp] => 1357668665 [rdf_mapping] => Array ( )
) ) ) [field_author] => Array ( [und] => Array ( [0] => Array ( [value] => John B.
Romesier [format] => [safe_value] => John B. Romesier ) ) ) [field_publisher] => Array
( [und] => Array ( [0] => Array ( [value] => Unknown [format] => [safe_value] =>
Unknown ) ) ) [field_release_date] => Array ( [und] => Array ( [0] => Array ( [value]
=> Mar 2012 [format] => [safe_value] => Mar 2012 ) ) ) [field_number_of_pages] => Array
( [und] => Array ( [0] => Array ( [value] => 123 ) ) ) [field_catagory] => Array (
[und] => Array ( [0] => Array ( [tid] => 4 ) ) ) [field_book_type] => Array ( [und] => Array ( [0] => Array ( [tid] => 1 ) ) ) [field_isbn] => Array ( ) [field_about_the_author] => Array ( [und] => Array ( [0] => Array ( [value] => Beachhed Don authoer............................ [format] => [safe_value] => Beachhed Don authoer............................ ) ) ) [rdf_mapping] => Array ( [rdftype] => Array ( [0] => sioc:Item [1] => foaf:Document ) [title] => Array ( [predicates] => Array ( [0] => dc:title ) ) [created] => Array ( [predicates] => Array ( [0] => dc:date [1] => dc:created ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [changed] => Array ( [predicates] => Array ( [0] => dc:modified ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [body] => Array ( [predicates] => Array ( [0] => content:encoded ) ) [uid] => Array ( [predicates] => Array ( [0] => sioc:has_creator ) [type] => rel ) [name] => Array ( [predicates] => Array ( [0] => foaf:name ) ) [comment_count] => Array ( [predicates] => Array ( [0] => sioc:num_replies ) [datatype] => xsd:integer ) [last_activity] => Array ( [predicates] => Array ( [0] => sioc:last_activity_date ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) ) [cid] => 0 [last_comment_timestamp] => 1357668665 [last_comment_name] => [last_comment_uid] => 1 [comment_count] => 0 [name] => admin [picture] => 0 [data] => b:0; [entity_view_prepared] => 1 )
I am trying to retrive the [value] of Description info ))))))))))))))))))))))))))))))))))))))0
I tried this
<?php
$node = menu_get_object(); //drupal code
if ( !empty($node) ) {
print $node ->body=>und=>0=>value;
}?>
and got an error about the '=' sign. What is the proper way to get my data?
[body] and [und] are arrays, so access them like this:
echo $node->body['und'][0]['value'];
It should be:
$node->body['und'][0]['value']
'Body' and 'und' are Arrays and need to be accessed with array syntax([]).
Accessing these values directly is sometimes frowned upon in drupal. You may want to look into: http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_render/7

Pull out a PHP variable in a complex nested array (from a Drupal View) [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Able to see a variable in print_r()'s output, but not sure how to access it in code
I've got a complex array variable called $data. I need to pull out one very buried value: [url] in [field_website]. Here's the raw print_r() output of the $data variable:
stdClass Object ( [node_title] => CMI2 [nid] => 3 [field_data_field_website_node_entity_type] => node [field_data_field_blog_node_entity_type] => node [field_data_field_rss_node_entity_type] => node [field_data_field_twitter_node_entity_type] => node [field_data_field_yammer_node_entity_type] => node [field_data_field_facebook_node_entity_type] => node [field_data_field_flickr_node_entity_type] => node [field_data_field_youtube_node_entity_type] => node [_field_data] => Array ( [nid] => Array ( [entity_type] => node [entity] => stdClass Object ( [vid] => 3 [uid] => 1 [title] => CMI2 [log] => [status] => 1 [comment] => 1 [promote] => 0 [sticky] => 0 [nid] => 3 [type] => social_source [language] => und [created] => 1356040541 [changed] => 1356040541 [tnid] => 0 [translate] => 0 [revision_timestamp] => 1356040541 [revision_uid] => 1 [field_website] => Array ( [und] => Array ( [0] => Array ( [url] => http://cmi2.yale.edu [title] => [attributes] => Array ( ) ) ) ) [field_blog] => Array ( ) [field_rss] => Array ( ) [field_twitter] => Array ( [und] => Array ( [0] => Array ( [url] => http://twitter.com/yalecmi2 [title] => [attributes] => Array ( ) ) ) ) [field_facebook] => Array ( ) [field_youtube] => Array ( ) [field_flickr] => Array ( ) [field_yammer] => Array ( ) [rdf_mapping] => Array ( [rdftype] => Array ( [0] => sioc:Item [1] => foaf:Document ) [title] => Array ( [predicates] => Array ( [0] => dc:title ) ) [created] => Array ( [predicates] => Array ( [0] => dc:date [1] => dc:created ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [changed] => Array ( [predicates] => Array ( [0] => dc:modified ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [body] => Array ( [predicates] => Array ( [0] => content:encoded ) ) [uid] => Array ( [predicates] => Array ( [0] => sioc:has_creator ) [type] => rel ) [name] => Array ( [predicates] => Array ( [0] => foaf:name ) ) [comment_count] => Array ( [predicates] => Array ( [0] => sioc:num_replies ) [datatype] => xsd:integer ) [last_activity] => Array ( [predicates] => Array ( [0] => sioc:last_activity_date ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) ) [cid] => 0 [last_comment_timestamp] => 1356040541 [last_comment_name] => [last_comment_uid] => 1 [comment_count] => 0 [name] => admin [picture] => 0 [data] => b:0; ) ) ) [field_field_website] => Array ( [0] => Array ( [rendered] => Array ( [#markup] => http://cmi2.yale.edu [#access] => 1 ) [raw] => Array ( [url] => http://cmi2.yale.edu [title] => http://cmi2.yale.edu [attributes] => Array ( ) [display_url] => http://cmi2.yale.edu ) ) ) [field_field_blog] => Array ( ) [field_field_rss] => Array ( ) [field_field_twitter] => Array ( [0] => Array ( [rendered] => Array ( [#markup] => http://twitter.com/yalecmi2 [#access] => 1 ) [raw] => Array ( [url] => http://twitter.com/yalecmi2 [title] => http://twitter.com/yalecmi2 [attributes] => Array ( ) [display_url] => http://twitter.com/yalecmi2 ) ) ) [field_field_yammer] => Array ( ) [field_field_facebook] => Array ( ) [field_field_flickr] => Array ( ) [field_field_youtube] => Array ( ) )
(sorry about that ugliness!)
How the heck do I pull out that [url] variable?! Ideally, I just want to assign that one value to another variable or just print it out.
If it's helpful, this is from a Drupal 7 view with the Views PHP module.
Thanks!
I recommend reading up about PHP arrays and objects since what you are trying to do is so trivial.
http://php.net/manual/en/language.types.array.php
http://php.net/manual/en/sdo.sample.getset.php

merge arrays within two arrays that share a common index - php

I have two arrays that have common indexes (church and office). I need to "merge" the total of the first array into the second array to get the desired output (seen below the double line). I'm not sure how to do this with array_merge(). Any help would be greatly appreciated!
Array
(
[church] => Array
(
[total] => 77
)
[office] => Array
(
[total] => 202
)
)
Array
(
[church] => Array
(
[name] => Array
(
[0] => Bill
[1] => Sally
)
[addr] => Array
(
[0] => Address Same as Billing
[1] => Address Same as Billing
)
[message] => Array
(
[0] =>
[1] =>
)
[amount] => Array
(
[0] => 25
[1] => 50
)
)
[office] => Array
(
[name] => Array
(
[0] => Marta
[1] => Ruth
)
[addr] => Array
(
[0] => Address Same as Billing
[1] => Address Same as Billing
)
[message] => Array
(
[0] =>
[1] =>
)
[amount] => Array
(
[0] => 100
[1] => 100
)
)
)
====================================================
Array
(
[church] => Array
(
[total] => 77
[name] => Array
(
[0] => Bill
[1] => Sally
)
[addr] => Array
(
[0] => Address Same as Billing
[1] => Address Same as Billing
)
[message] => Array
(
[0] =>
[1] =>
)
[amount] => Array
(
[0] => 25
[1] => 50
)
)
[office] => Array
(
[total] => 202
[name] => Array
(
[0] => Marta
[1] => Ruth
)
[addr] => Array
(
[0] => Address Same as Billing
[1] => Address Same as Billing
)
[message] => Array
(
[0] =>
[1] =>
)
[amount] => Array
(
[0] => 100
[1] => 100
)
)
)
Try something like this:
$a = array('church' => array('total' => 5), 'office' => array('total' => 10));
$b = array('church' => array('name' => 'church'), 'office' => array('name' => 'office'));
foreach ( $b as $key => $value ) {
$b[$key] = array_merge($a[$key], $b[$key]);
}

Categories