I asked this question few months ago but at that time i needed to pull just one membership level, now i need to pull every level name, here is array:
Array
(
[success] => 1
[member] => Array
(
[0] => Array
(
[Levels] => Array
(
[1391447566] => stdClass Object
(
[Level_ID] => 1391447566
[Name] => Team Membership
[Cancelled] =>
[CancelDate] =>
[Pending] =>
[UnConfirmed] =>
[Expired] =>
ExpiryDate] => 1397266537
[SequentialCancelled] =>
[Active] => 1
[Status] => Array
(
[0] => Active
)
[Timestamp] => 1394588137
[TxnID] => WL-1-1391447566
)
[1391540448] => stdClass Object
(
[Level_ID] => 1391540448
[Name] => Gold Training Membership
[Cancelled] =>
[CancelDate] =>
[Pending] =>
[UnConfirmed] =>
[Expired] =>
[ExpiryDate] => 1396642789
[SequentialCancelled] =>
[Active] => 1
[Status] => Array
(
[0] => Active
)
[Timestamp] => 1393967989
[TxnID] => WL-1-1391540448
)
[1391540567] => stdClass Object
(
[Level_ID] => 1391540567
[Name] => Platinum Training Membership
[Cancelled] =>
[CancelDate] =>
[Pending] =>
[UnConfirmed] =>
[Expired] =>
[ExpiryDate] => 1397302237
[SequentialCancelled] =>
[Active] => 1
[Status] => Array
(
[0] => Active
)
[Timestamp] => 1394623837
[TxnID] => WL-1-1391540567
)
)
[PayPerPosts] => Array
(
)
)
)
[supported_verbs] => Array
(
[0] => GET
[1] => PUT
[2] => DELETE
)
)
What I need is to pull Name of Level which is inside an object that has diffrent number every time and add it to an array which i need to save in DB. One solution, just to pull info, wass:
foreach ($response["member"][0]["Levels"] AS $level_key => $level_val) {
$level_name = $level_key->Name;
echo 'Name: '.$level_name;
}
but its not pulling anything, just echoing "name" 3 times.
This was the code i used to pull only one name:
$levels = $response["member"][0]["Levels"];
$firstLevel = array_shift(array_values($levels));
$membership = $firstLevel->Name;
Thanks!
Just try with:
$level_name = $level_val->Name;
$level_key is an integer value with level ID (?). $level_val is your level object with data.
Related
I'm trying to get the first deal ID from AgileCRM.
When using:
$test = json_decode($deal, true);
print_r($test);
I get the following result:
Array (
[0] => Array (
[colorName] => WHITE
[id] => 5686812383117312
[apply_discount] =>
[discount_value] => 0
[discount_amt] => 0
[discount_type] => Value
[name] => New Home Loan
[contact_ids] => Array (
[0] => 5645056174194688
)
[custom_data] => Array (
)
[products] => Array (
)
[description] => New Lead
[expected_value] => 0
[milestone] => New Loan
[probability] => 10
[close_date] => 1521192269
[created_time] => 1510824270
[milestone_changed_time] => 0
[entity_type] => deal
[notes] => Array (
)
[note_ids] => Array (
)
[note_created_time] => 0
[pipeline_id] => 5719238044024832
[archived] =>
[lost_reason_id] => 0
[deal_source_id] => 0
[total_deal_value] => 0
[updated_time] => 1510824270
[isCurrencyUpdateRequired] => 1
[currency_conversion_value] => 0
[tags] => Array (
)
[tagsWithTime] => Array (
)
[contacts] => Array (
[0] => Array (
[id] => 5645056174194688
[type] => PERSON
[properties] => Array (
[0] => Array (
[type] => SYSTEM
[name] => first_name
[value] => piet
)
[1] => Array (
[type] => SYSTEM
[name] => last_name
[value] => pompies
)
[2] => Array (
[type] => SYSTEM
[name] => name
[value] =>
)
)
)
)
[owner] => Array (
[id] => 5178546118721536
[domain] => domainname
[email] => myemail#email.com
[phone] =>
[name] => Piet Pompies
[pic] => https://d1gwclp1pmzk26.cloudfront.net/img/gravatar/48.png
[schedule_id] => Piet Pompies
[calendar_url] => https://homeside.agilecrm.com/calendar/Piet_Pompies
[calendarURL] => https://homeside.agilecrm.com/calendar/Piet_Pompies
)
)
)
I want to echo "5686812383117312" from "[id] => 5686812383117312" (4th line in the array above)
I've tried "foreach" statements but my expertise on it is limited and can't seem to get it right.
Any help will be appreciated.
In order to access the ID field you should:
get the array's first key
Access the required field
Array:
Array ( //$test
[0] => Array ( //first key [0]
[colorName] => WHITE
[id] => 5686812383117312 //the required field ['id']
[apply_discount] =>
PHP:
$test = json_decode($deal, true);
print_r($test);
echo $test[0]['id']; //Output: 5686812383117312
I am trying to get the value of bank_name in php. Can't get it to display.
stdClass Object ( [account_id] => 43726384 [name] => Account Name [state] => action_required [description] => [owner_user_id] =>[type] => personal [create_time] => 1477684534 [disablement_time] => [country] => US [currencies] => Array ( [0] => USD ) [action_reasons] => Array ( [0] => kyc [1] => bank_account ) [disabled_reasons] => Array ( ) [image_uri] => [supported_card_types] => Array ( [0] => visa [1] => mastercard [2] => american_express [3] => discover [4] => jcb [5] => diners_club ) [gaq_domains] => Array ( [0] => ) [balances] => Array ( [0] => stdClass Object ( [balance] => 0 [currency] => USD [disputed_amount] => 0 [incoming_pending_amount] => 0 [outgoing_pending_amount] => 0 [reserved_amount] => 0 [bank_name] => Bank Of America [withdrawal_next_time] => [withdrawal_period] => [withdrawal_type] => ) ) [statuses] => Array ( [0] => stdClass Object ( [currency] => USD [incoming_payments_status] => ok [outgoing_payments_status] => paused [account_review_status] => not_requested ) ) )
It's not very clear if you display data that way, but I think this would be the way to access to bank_name:
$bankName = $object->balances[0]->bank_name;
(If it doesn't work, please show the XML before parsing it to an object)
I have a working PHP app running in Bluemix that I want to extend to call a RESTful service (Insights for Twitter). I've been able to call the service, retrieve the json body, and use json_decode as follows to create an array:
$insightList = json_decode($guzzleResponse ->getBody(), true);
However, I can't figure out how to get access to the field I'm interested in. I've searched for solution on the web and tried a few approaches that looked promising, but when I tried to integrate them, I couldn't get them to work. I'm a bit of a PHP novice, so if something doesn't work I'm not sure how to proceed.
The json structure is quite complex, with three top-level arrays - search, tweets, and next. I'm interested in the second of these, tweets. It's a pretty complex array - there is one entry per tweet. The field I want right now is tweets.cde.message.body. You can find the full schema here: https://cdeservice.eu-gb.mybluemix.net/rest-api/#!/messages/getTweets
This is the code I have so far:
foreach($insightList as $cde) {
foreach($cde as $message) {
$insight = $message['body'];
if(strlen($insight) > 60) {
$posts[] = array(
'id' => 99999999,
//Temp; remove links from the text
'text' => $insight,
'category' => $insightCategory,
'image' => 'false'
);
}
}
}
Here's a print_r of $insightList:
[search] => Array (
[results] => 28
[current] => 28
)
[tweets] => Array (
[0] => Array (
[cde] => Array (
[author] => Array (
[gender] => male
[parenthood] => Array (
[isParent] => unknown
)
[location] => Array (
[country] =>
)
[maritalStatus] => Array (
[isMarried] => unknown
)
)
[content] => Array (
[sentiment] => Array (
[evidence] => Array ( )
[polarity] => NEUTRAL
)
)
)
[message] => Array (
[postedTime] => 2015-01-13T09:42:16.000Z
[verb] => share
[link] => http://twitter.com/zWDOM/statuses/554936456477933569
[generator] => Array (
[displayName] => Twitter Web Client
[link] => http://twitter.com
)
[body] => RT #VisualSuccess: "Mainframe & Cloud" Magazine wurde soeben publiziert! http://www.twitter.com #zWDOM #Rocket #JohnKnutson_IBM
[favoritesCount] => 0
[objectType] => activity
[actor] => Array (
[summary] => Seit über 25 Jahren im Mainframebereich, derzeit als Senior Consultant und IT Architekt für zEnterprise und Projektmanager beim IBM BP Cancom in Köln
[image] => https://pbs.twimg.com/profile_images/424202233463308288/XQquUcnh_normal.jpeg
[statusesCount] => 2309
[utcOffset] => 3600
[languages] => Array (
[0] => de
)
[preferredUsername] => zWDOM
[displayName] => Willi Domroese
[postedTime] => 2009-12-17T01:39:25.000Z
[link] => http://www.twitter.com/zWDOM
[verified] =>
)
[provider] => Array (
[displayName] => Twitter
[link] => http://www.twitter.com
[objectType] => service
)
[twitter_filter_level] => medium
[twitter_entities] => Array (
[urls] => Array (
[0] => Array (
[display_url] => ln.is/paper.li/visua…
[indices] => Array (
[0] => 77
[1] => 99
)
[expanded_url] => http://ln.is/paper.li/visualsucce/7zYNk
[url] => http://www.twitter.com
)
)
[hashtags] => Array ( )
[user_mentions] => Array (
[0] => Array (
[indices] => Array (
[0] => 3
[1] => 17
)
[screen_name] => VisualSuccess
[id_str] => 213337792
[name] => Predrag Gasic
[id] => 213337792
)
[1] => Array (
[indices] => Array (
[0] => 101
[1] => 107
)
[screen_name] => zWDOM
[id_str] => 97334013
[name] => Willi Domroese
[id] => 97334013
)
[2] => Array (
[indices] => Array (
[0] => 108
[1] => 115
)
[screen_name] => Rocket
[id_str] => 870584947
[name] => Rocket Software
[id] => 870584947
)
[3] => Array (
[indices] => Array (
[0] => 116
[1] => 132
)
[screen_name] => JohnKnutson_IBM
[id_str] => 16452310
[name] => John Knutson
[id] => 16452310
)
)
[trends] => Array ( )
[symbols] => Array ( )
)
[twitter_lang] => de
[id] => tag:search.twitter.com,2005:554936456477933569
[retweetCount] => 1
[gnip] => Array (
[urls] => Array (
[0] => Array (
[expanded_url] => http://linkis.com/paper.li/visualsucce/7zYNk
[expanded_status] => 200
[url] => http://www.twitter.com
)
)
[language] => Array (
[value] => de
)
)
[object] => Array (
[postedTime] => 2015-01-13T08:04:48.000Z
[verb] => post
[link] => http://twitter.com/VisualSuccess/statuses/554911928527888384
[generator] => Array (
[displayName] => Linkis.com
[link] => http://linkis.com
)
[body] => "Mainframe & Cloud" Magazine wurde soeben publiziert! http://www.twitter.com ://www.twitter.com
[objectType] => activity
[actor] => Array (
[summary] => Ù† (N), Wirtschaftsinformatiker | SAP Consultant Logistics #bigdata #appdevelopment #webdesign #eCommerce #SocialMedia #contentmarketing #SmartHome #Journal
[image] => https://pbs.twimg.com/profile_images/2841607223/959b0d23646b1f24bd7b70deac160e2f_normal.jpeg
[statusesCount] => 14185
[utcOffset] => 3600
[languages] => Array (
[0] => de
)
[preferredUsername] => VisualSuccess
[displayName] => Predrag Gasic
[postedTime] => 2010-11-08T17:19:27.000Z
[link] => http://www.twitter.com/VisualSuccess
[verified] =>
)
[provider] => Array (
[displayName] => Twitter
[link] => http://www.twitter.com
[objectType] => service
)
[twitter_filter_level] => low
[twitter_entities] => Array (
[urls] => Array (
[0] => Array (
[display_url] => ln.is/paper.li/visua…
[indices] => Array (
[0] => 58
[1] => 80
)
[expanded_url] => http://ln.is/paper.li/visualsucce/7zYNk
[url] => http://www.twitter.com
)
)
[hashtags] => Array ( )
[user_mentions] => Array (
[0] => Array (
[indices] => Array (
[0] => 82
[1] => 88
)
[screen_name] => zWDOM
[id_str] => 97334013
[name] => Willi Domroese
[id] => 97334013
)
[1] => Array (
[indices] => Array (
[0] => 89
[1] => 96
)
[screen_name] => Rocket
[id_str] => 870584947
[name] => Rocket Software
[id] => 870584947
)
[2] => Array (
[indices] => Array (
[0] => 97
[1] => 113
)
[screen_name] => JohnKnutson_IBM
[id_str] => 16452310
[name] => John Knutson
[id] => 16452310
)
)
[trends] => Array ( )
[symbols] => Array (
)
)
)
)
)
Answers to this question would be greatly appreciated
Iterating $insightList will not get you to the cde level. And you don't actually want the cde; you want the message.
Just iterate the tweets. You don't need a foreach to get keyed info from a PHP array.
foreach($insightList['tweets'] as $tweet) {
$insight = $tweet['message']['body'];
if(strlen($insight) > 60) {
$posts[] = array(
'id' => 99999999,
//Temp; remove links from the text
'text' => $insight,
'category' => $insightCategory,
'image' => 'false'
);
}
}
It looks to me from your print_r that what you want is at:
echo $insightList[0]['message']['body'];
When there's a section like this [some_key], then 'some_key' is an associative array key, and you can access those elements be they additional arrays or a value, using the key name, as I illustrated here.
Jcart Object(
[config] => Array
(
[jcartPath] => jcart/
[checkoutPath] => checkout.php
[item] => Array
(
[id] => my-item-id
[name] => my-item-name
[price] => my-item-price
[qty] => my-item-qty
[url] => my-item-url
[add] => my-add-button
)
[paypal] => Array
(
[id] => seller_1282188508_biz#conceptlogic.com
[https] => 1
[sandbox] =>
[returnUrl] =>
[notifyUrl] =>
)
[currencyCode] => USD
[csrfToken] =>
[text] => Array
(
[cartTitle] => Shopping Cart
[singleItem] => Item
[multipleItems] => Items
[subtotal] => Subtotal
[update] => update
[checkout] => checkout
[checkoutPaypal] => Checkout with PayPal
[removeLink] => remove
[emptyButton] => empty
[emptyMessage] => Your cart is empty!
[itemAdded] => Item added!
[priceError] => Invalid price format!
[quantityError] => Item quantities must be whole numbers!
[checkoutError] => Your order could not be processed!
)
[button] => Array
(
[checkout] =>
[paypal] =>
[update] =>
[empty] =>
)
[tooltip] => 1
[decimalQtys] =>
[decimalPlaces] => 1
[priceFormat] => Array
(
[decimals] => 2
[dec_point] => .
[thousands_sep] => ,
)
)
[items] => Array
(
[0] => 3
[1] => poslaju
)
[names] => Array
(
[3] => Hockey Stick
[poslaju] => Pos Laju
)
[prices] => Array
(
[3] => 33.25
[poslaju] => 6.00
)
[qtys] => Array
(
[3] => 1
[poslaju] => 3
)
[urls] => Array
(
[3] => http://bing.com
[poslaju] =>
)
[subtotal] => 51.25
[itemCount] => 4
)
Im using print_r($jcart) to get the result above.
i just want to print out [qtys] array. i have try print_r($qtys); but it's not working.
You have to reference the array element. So you'll always need to point to $jcart and then reference from there. As Sergey pointed out, you've got an object there
Jcart Object
So you'll have to reference the element of the object, not an array
print_r($jcart->qtys);
use the reference key for selecting that particular element u need.
echo '<pre>'; print_r($jcart->qtys);
<pre> tag is just added to view the array in a better format
I'm working with the the fb page and I have pulled posts from a use using:
$fbapp = PVConfiguration::getConfiguration('afbapp');
$facebook = new Facebook( array('appId' => $fbapp -> app_id, 'secret' => $fbapp -> app_secret, 'cookie' => true ));
$facebook->api( $this -> fb_page_id . '/feed');
Now a sample result looks something like this:
[0] => Array
(
[id] => 311007125672751_315405295232910
[from] => Array
(
[category] => Retail and consumer merchandise
[name] => Example Demos
[id] => 311007125672751
)
[story] => Phonefare Demos added a new photo.
[story_tags] => Array
(
[0] => Array
(
[0] => Array
(
[id] => 311007125672751
[name] => Example Demos
[offset] => 0
[length] => 15
[type] => page
)
)
)
[picture] => https://fbcdn-photos-e-a.akamaihd.net/hphotos-ak-ash2/576447_315405255232904_1958203550_s.jpg
[link] => https://www.facebook.com/photo.php?fbid=315405255232904&set=a.315405251899571.62826.311007125672717&type=1&relevant_count=1
[icon] => https://static.xx.fbcdn.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif
[actions] => Array
(
[0] => Array
(
[name] => Comment
[link] => https://www.facebook.com/311007125672751/posts/315405295232910
)
[1] => Array
(
[name] => Like
[link] => https://www.facebook.com/311007125672751/posts/315405295232910
)
)
[privacy] => Array
(
[description] => Public
[value] => EVERYONE
[friends] =>
[networks] =>
[allow] =>
[deny] =>
)
[type] => photo
[status_type] => added_photos
[object_id] => 315405255232904
[created_time] => 2012-12-21T15:04:37+0000
[updated_time] => 2012-12-21T15:04:37+0000
[shares] => Array
(
[count] => 2
)
[likes] => Array
(
[data] => Array
(
[0] => Array
(
[id] => 45608554
[name] => Michele A
)
)
[paging] => Array
(
[cursors] => Array
(
[after] => NDU2MDg1NjY=
[before] => NDU2MDg1NjY=
)
)
)
)
My greatest point of confusion is this. I want to store the post in the database as a bigint. But the return id is
311007125672751_315405295232910
, and I'm guessing its two IDS. So which ID should I be storing in the database to reference later? What are both IDs for? Is there a fundamental flaw for breaking the IDS apart to start them as BigInts/UUIDs?