Related
this is my response
i need to read first line id value & url of sandbox
{
"id": "chg_g5Y25220190539Ob590811651",
"object": "charge",
"live_mode": false,
"api_version": "V2",
"method": "CREATE",
"status": "INITIATED",
"amount": 1.000,
"currency": "KWD",
"threeDSecure": false,
"card_threeDSecure": false,
"save_card": false,
"statement_descriptor": "Sample",
"description": "Test DESC",
"transaction":
{
"timezone": "UTC+03:00",
"created": "1573191592651",
"url": "https://sandbox.payments.tap.company/test_gosell/v2/payment/response.aspx?tap_chg=PsV8hZdr78kEIAOZl9XL1B5u3dXe%2bBQ%2b3Hrd%2fempxYs%3d&sess=noWi606EI%2bM%3d&token=PsV8hZdr78kEIAOZl9XL1B5u3dXe%2bBQ%2bTyYdQy9iGpS6aAXwKOqAdw%3d%3d",
"expiry": { "period": 30, "type": "MINUTE" },
"asynchronous": false
},
"reference": { "transaction": "txn_0001", "order": "ord_0001" },
"response": { "code": "100", "message": "Initiated" },
"receipt": { "email": true, "sms": true },
"customer": { "first_name": "yxy", "last_name": "ttt", "email": "xyx#xyz.com" },
"source": { "object": "source", "id": "src_card" },
"redirect": { "status": "PENDING", "url": "http://localhost:81/School/" },
"post": { "status": "PENDING", "url": "http://localhost:81/School/" } }
assuming you have your response from curl in a variable called $resp
$resp_decoded = json_decode($resp,TRUE);
print($resp_decoded['id']);
print($resp_decoded['transaction']['url']);
This is step 1. These are the input boxes i want to type. This is the function I created to point each value to input boxes:
getmyEditor: function(){
this.chartType = this.options.chart.type;
this.backgroundColor = this.options.chart.backgroundColor;
this.borderColor = this.options.chart.borderColor;
this.borderWidth = this.options.chart.borderWidth;
this.height = this.options.chart.height;
this.options.xAxis.plotLines = [{
value: this.xPlotLinesvalue,
label: {
text: this.xPlotLinesText,
align: 'center',
style: {
color: 'gray'
}
}}];
Above code i created to access object values. how to apply this values added
text boxes?
{"chart": {
"type": "pie",
"backgroundColor": "#FFFFFF",
"borderColor": "#000",
"borderWidth": 0,
"height": 300,
"inverted": false,
"plotBackgroundColor": "#FFFFFF",
"plotBorderColor": "#FFFFFF",
"plotBorderWidth": 1,
"style": {
"fontFamily": "Open Sans"
},
"polar": ""
},
"title": {
"text": "Title",
"x": -20
},
"table": {
"text": ""
},
"xAxis": {
"max": null,
"categories": [],
"title": {
"text": ""
},
"plotLines": [
{
"value": 0,
"width": 0,
"color": "red",
"label": {
"text": "",
"align": "center",
"style": {
"color": "gray"
}
}
}
]
},
"yAxis": {
"title": {
"text": ""
},
"categories": [],
"min": null,
"max": null,
"plotLines": [
{
"value": 0,
"width": 0,
"color": "red",
"label": {
"text": "",
"align": "center",
"style": {
"color": "gray"
}
}
}
]
},
"zAxis": "",
"tooltip": {
"valueDecimals": 0,
"valuePrefix": "",
"valueSuffix": "",
"padding": 8
},
"legend": {
"enabled": true,
"layout": "vertical",
"align": "right",
"verticalAlign": "middle",
"borderWidth": 0
},
"credits": {
"enabled": false
},
"plotOptions": {
"series": {
"color": "#582b6e",
"stacking": "",
"point": {
"events": {}
}
},
"scatter": {
"marker": {
"radius": 4,
"states": {
"hover": {
"enabled": true,
"lineColor": "rgb(100,100,100)"
}
}
},
"states": {
"hover": {
"marker": {
"enabled": false
}
}
},
"tooltip": {
"headerFormat": "<b>{series.name}</b><br>",
"pointFormat": "{point.x} , {point.y} ",
"x_unit": "",
"y_unit": ""
}
}
},
"series": [
{
"name": "Brands",
"colorByPoint": true,
"data": [
{
"name": "IE",
"y": 56.33
},
{
"name": "Chrome",
"y": 24.03,
"sliced": true,
"selected": true
},
{
"name": "Firefox",
"y": 10.38
},
{
"name": "Safari",
"y": 4.77
},
{
"name": "Opera",
"y": 0.91
},
{
"name": "Other",
"y": 0.2
}
]
}
],
"lang": {
"noData": "NO DATA AVAILABLE!"
},
"noData": {
"style": {
"fontWeight": "bold",
"fontSize": "15px",
"color": "#303030"
}
}
}
I'm trying to access (point to text boxes) this object using vue, but it's not working yet. How to do that correctly? I point each object value using this vue function inside method.
This is i want final output: This object view inside textarea if i change text area object value then that value will going to above input boxes.
I am using php wrapper, try create an item, all is ok, item is creating, but I can't change status, tried different ways, but can't find right way.
Need change status to "Closed" - http://prntscr.com/fsrwc3
Codes not works:
$fields = new PodioItemFieldCollection([
new PodioCategoryItemField(['external_id'=>'status', 'values'=>13]),
]);
$item = new PodioItem([
'app' => new PodioApp($app_id),
'fields' => $fields
]);
$item->save();
or
$fields = new PodioItemFieldCollection([
new PodioCategoryItemField(['external_id'=>'status', 'values'=>13]),
]);
$item = new PodioItem([
'app' => new PodioApp($app_id),
'fields' => $fields
]);
$item->save();
$get_item = PodioItem::get_basic($item->item_id);
$get_item->fields['status']->values = ['id'=>13];
$get_item->save();
After create item (after new PodioItem...), if I get fields after this code (just get $item->fields or PodioItem::get_basic...), I can see correct status, only in the code, only immediatly after create item, but if I get this item in the another code (just PodioItem::get_basic...) I will see default value, so code don't change status, looks like I just see some cache.
If I create item on the one script:
$fields = new PodioItemFieldCollection([
new PodioCategoryItemField(['external_id'=>'status', 'values'=>13]),
]);
$item = new PodioItem([
'app' => new PodioApp($app_id),
'fields' => $fields
]);
$item->save();
Then, in the another script update field, it will be change:
$get_item = PodioItem::get_basic('639637317');
$get_item->fields['status']->values = ['id'=>13];
$get_item->save();
Update - debug information:
Get log by test code -
PodioItem::create($app_id, ['fields' => ['status'=>[13], 'category'=>[3], 'contract-type'=>[4]]]);
(simple variant for creating an item, have the same problems like new PodioItem... )
All fields have category type, but:
status - have inline show type - don't chnages
category - have dropdown show type - Is changing
contract-type - have dropdown show type - Is changing
Log:
2017-07-08 11:07:22 200 POST /item/app/12152727/
2017-07-08 11:07:22 Request body: {"fields":{"status":[8],"category":[3],"contract-type":[4]}}
2017-07-08 11:07:22 Reponse: {
"presence": {
"ref_type": "item",
"ref_id": 641331142,
"user_id": 4194774,
"signature": "c165b85090e6ad28e74ae4baf93ee56113f88bc9"
},
"app": {
"status": "active",
"sharefile_vault_url": null,
"name": "Projects",
"default_view_id": null,
"url_add": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects\/items\/new",
"icon_id": 378,
"link_add": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects\/items\/new",
"app_id": 12152727,
"current_revision": 141,
"item_name": "Project",
"link": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects",
"url": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects",
"url_label": "projects",
"config": {
"item_name": "Project",
"icon_id": 378,
"type": "standard",
"name": "Projects",
"icon": "378.png"
},
"space_id": 3466816,
"icon": "378.png"
},
"created_on": "2017-07-10 15:31:16",
"last_event_on": "2017-07-10 15:31:16",
"linked_account_data": null,
"sharefile_vault_folder_id": null,
"app_item_id_formatted": "3988",
"recurrence": null,
"title": "ACSC",
"participants": {},
"created_by": {
"user_id": 4194774,
"name": "Anton Mikhailov",
"url": "https:\/\/podio.com\/users\/4194774",
"type": "user",
"image": null,
"avatar_type": "file",
"avatar": null,
"id": 4194774,
"avatar_id": null,
"last_seen_on": "2017-07-10 15:31:15"
},
"priority": 641331142.0,
"created_via": {
"url": null,
"auth_client_id": 25162,
"display": true,
"name": "importer",
"id": 25162
},
"subscribed_count": 1,
"reminder": null,
"ref": null,
"revision": 0,
"app_item_id": 3988,
"link": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects\/items\/3988",
"item_id": 641331142,
"sharefile_vault_url": null,
"rights": ["subscribe", "grant", "add_conversation", "rate", "update", "delete", "add_file", "grant_view", "view", "comment", "add_task"],
"fields": [{
"status": "active",
"type": "category",
"field_id": 93352415,
"label": "Division",
"values": [{
"value": {
"status": "active",
"text": "ACSC",
"id": 3,
"color": "D2E4EB"
}
}],
"config": {
"default_value": null,
"unique": false,
"description": null,
"hidden_create_view_edit": false,
"required": true,
"mapping": null,
"label": "Division",
"visible": true,
"delta": 5,
"hidden": false,
"settings": {
"multiple": false,
"options": [{
"status": "active",
"text": "ACSE",
"id": 1,
"color": "DCEBD8"
}, {
"status": "active",
"text": "ACSB",
"id": 2,
"color": "F7F0C5"
}, {
"status": "active",
"text": "ACSC",
"id": 3,
"color": "D2E4EB"
}],
"display": "dropdown"
}
},
"external_id": "category"
}, {
"status": "active",
"type": "category",
"field_id": 148215928,
"label": "Contract Type",
"values": [{
"value": {
"status": "active",
"text": "No Contract",
"id": 4,
"color": "DDDDDD"
}
}],
"config": {
"default_value": null,
"unique": false,
"description": null,
"hidden_create_view_edit": false,
"required": true,
"mapping": null,
"label": "Contract Type",
"visible": true,
"delta": 7,
"hidden": false,
"settings": {
"multiple": false,
"options": [{
"status": "active",
"text": "PO \/ Purchase \/ T&M",
"id": 1,
"color": "FFD5C2"
}, {
"status": "active",
"text": "Original Contract",
"id": 2,
"color": "D2E4EB"
}, {
"status": "active",
"text": "Service Rider",
"id": 3,
"color": "DCEBD8"
}, {
"status": "active",
"text": "No Contract",
"id": 4,
"color": "DDDDDD"
}],
"display": "dropdown"
}
},
"external_id": "contract-type"
}, {
"status": "active",
"type": "category",
"field_id": 93034840,
"label": "Instal Status",
"values": [{
"value": {
"status": "active",
"text": "Closed",
"id": 13,
"color": "E1D8ED"
}
}],
"config": {
"default_value": null,
"unique": false,
"description": null,
"hidden_create_view_edit": false,
"required": true,
"mapping": null,
"label": "Instal Status",
"visible": true,
"delta": 13,
"hidden": false,
"settings": {
"multiple": false,
"options": [{
"status": "deleted",
"text": "To Be Reviewed",
"id": 2,
"color": "F7F0C5"
}, {
"status": "deleted",
"text": "ACS Accounting Review",
"id": 5,
"color": "FFD5C2"
}, {
"status": "deleted",
"text": "Ignite Setup",
"id": 10,
"color": "DCEBD8"
}, {
"status": "active",
"text": "To Be Scheduled",
"id": 8,
"color": "D2E4EB"
}, {
"status": "active",
"text": "In Progress",
"id": 6,
"color": "DCEBD8"
}, {
"status": "active",
"text": "Warranty",
"id": 11,
"color": "F7F0C5"
}, {
"status": "active",
"text": "Complete",
"id": 3,
"color": "D1F3EC"
}, {
"status": "deleted",
"text": "Closed",
"id": 7,
"color": "DDDDDD"
}, {
"status": "active",
"text": "Cancelled",
"id": 9,
"color": "DDDDDD"
}, {
"status": "deleted",
"text": "VA in Progress",
"id": 4,
"color": "E1D8ED"
}, {
"status": "deleted",
"text": "Submitted",
"id": 1,
"color": "F7F0C5"
}, {
"status": "active",
"text": "On Hold",
"id": 12,
"color": "F7D1D0"
}, {
"status": "active",
"text": "Closed",
"id": 13,
"color": "E1D8ED"
}],
"display": "inline"
}
},
"external_id": "status"
}],
"initial_revision": {
"item_revision_id": 1664054437,
"created_via": {
"url": null,
"auth_client_id": 25162,
"display": true,
"name": "importer",
"id": 25162
},
"created_by": {
"user_id": 4194774,
"name": "Anton Mikhailov",
"url": "https:\/\/podio.com\/users\/4194774",
"type": "user",
"image": null,
"avatar_type": "file",
"avatar": null,
"id": 4194774,
"avatar_id": null,
"last_seen_on": "2017-07-10 15:31:15"
},
"created_on": "2017-07-10 15:31:16",
"user": {
"user_id": 4194774,
"name": "Anton Mikhailov",
"url": "https:\/\/podio.com\/users\/4194774",
"type": "user",
"image": null,
"avatar_type": "file",
"avatar": null,
"id": 4194774,
"avatar_id": null,
"last_seen_on": "2017-07-10 15:31:15"
},
"type": "creation",
"revision": 0
},
"current_revision": {
"item_revision_id": 1664054437,
"created_via": {
"url": null,
"auth_client_id": 25162,
"display": true,
"name": "importer",
"id": 25162
},
"created_by": {
"user_id": 4194774,
"name": "Anton Mikhailov",
"url": "https:\/\/podio.com\/users\/4194774",
"type": "user",
"image": null,
"avatar_type": "file",
"avatar": null,
"id": 4194774,
"avatar_id": null,
"last_seen_on": "2017-07-10 15:31:15"
},
"created_on": "2017-07-10 15:31:16",
"user": {
"user_id": 4194774,
"name": "Anton Mikhailov",
"url": "https:\/\/podio.com\/users\/4194774",
"type": "user",
"image": null,
"avatar_type": "file",
"avatar": null,
"id": 4194774,
"avatar_id": null,
"last_seen_on": "2017-07-10 15:31:15"
},
"type": "creation",
"revision": 0
},
"linked_account_id": null,
"push": {
"timestamp": 1499700676,
"expires_in": 21600,
"channel": "\/item\/641331142",
"signature": "b8a816ff367da6bc730071c875ca3fdca2d2c344"
},
"external_id": null
}
Have you tried http://podio.github.io/podio-php/fields/#category-field ?
Setting values
Set a single value by using the option_id. You can also
add a value with add_value()
$item = PodioItem::get_basic(123);
$field_id = 'category';
// Set value to a single option
$item->fields[$field_id]->values = 4; // option_id=4
// Add value to existing selection
$item->fields[$field_id]->add_value(4); // option_id=4
Use an array to set multiple values
$item = PodioItem::get_basic(123);
$field_id = 'category';
$item->fields[$field_id]->values = array(4,5,6); // option_ids: 4, 5 and 6
Creating item with value:
$fields = new PodioItemFieldCollection([
new PodioCategoryItemField(['external_id'=>'status', 'values'=>array(13)]),
]);
$item = new PodioItem([
'app' => new PodioApp($app_id),
'fields' => $fields
]);
$item->save();
The situation is I have two arrays that is collecting JSON data via the API :
$players = getAPI("http://xx.xxx.xxx.xx:xxxxx/players.json?apiKey=xxxxxxxxxxxxxxxxxxxxxxxx");
$recents = getAPI("xx.xxx.xxx.xx:xxxxx/recent.json?apiKey=xxxxxxxxxxxxxxxxxxxxxxxx");
The method is getting the contents and decoding the JSON into an array.
For the players array we have this data in an array:
$players
[
{
"id": "76561198033377272",
"name": "PitMonk",
"position": {
"x": -339,
"y": 26,
"z": 191
},
"rotation": 128,
"time": 418310,
"ip": "",
"inventory": {
"main": [],
"belt": [
{
"name": "rock",
"amount": 1,
"blueprint": false,
"condition": 100
},
{
"name": "torch",
"amount": 1,
"blueprint": false,
"condition": 100
}
],
"wear": []
}
},
{
"id": "76561198088638439",
"name": "Pippa",
"position": {
"x": -337,
"y": 25,
"z": 177
},
"rotation": 73,
"time": 419136,
"ip": "",
"inventory": {
"main": [
{
"name": "arrow.wooden",
"amount": 12,
"blueprint": false
},
{
"name": "bow.hunting",
"amount": 1,
"blueprint": false,
"condition": 93
},
{
"name": "blueprint_fragment",
"amount": 25,
"blueprint": false
},
{
"name": "metal.fragments",
"amount": 1366,
"blueprint": false
},
{
"name": "metal.refined",
"amount": 48,
"blueprint": false
},
{
"name": "charcoal",
"amount": 1120,
"blueprint": false
},
{
"name": "lowgradefuel",
"amount": 738,
"blueprint": false
}
],
"belt": [
{
"name": "rock",
"amount": 1,
"blueprint": false,
"condition": 100
},
{
"name": "torch",
"amount": 1,
"blueprint": false,
"condition": 100
},
{
"name": "pickaxe",
"amount": 1,
"blueprint": false,
"condition": 76
},
{
"name": "pickaxe",
"amount": 1,
"blueprint": false,
"condition": 17
},
{
"name": "pickaxe",
"amount": 1,
"blueprint": false,
"condition": 100
},
{
"name": "pickaxe",
"amount": 1,
"blueprint": false,
"condition": 100
}
],
"wear": [
{
"name": "burlap.shirt",
"amount": 1,
"blueprint": false
},
{
"name": "attire.hide.skirt",
"amount": 1,
"blueprint": false
}
]
}
}
]
$recents
[
{
"id": "76561198039206786",
"name": "JakeGroves"
},
{
"id": "76561198088638439",
"name": "Pippa"
},
{
"id": "76561198033377272",
"name": "PitMonk"
},
{
"id": "76561198146864439",
"name": "YepWellDone"
},
{
"id": "76561198164836207",
"name": "Baz"
},
{
"id": "76561198076406281",
"name": "xwalnutx"
},
{
"id": "76561197985716090",
"name": "Darkflame134"
},
{
"id": "76561198263423842",
"name": "XitaikiznerX"
},
{
"id": "76561198129952244",
"name": "NatanGamer"
},
{
"id": "76561198071842055",
"name": "Baha Bey"
}
]
As you can see the players is the people connected, and recents is the total list of people who have connected recently.
I have attempted this:
foreach ($players as $player) {
echo $players->name;
}
echo "</br></br>";
foreach ($recent as $rec) {
if ($rec->name != $player->name) {
echo $rec->name . "</br>";
}
}
and it produces the result:
PitMonk Pippa
JakeGroves
PitMonk
YepWellDone
Baz
xwalnutx
Darkflame134
XitaikiznerX
NatanGamer
Baha Bey
So it is only ignoring 'pippa', I am not sure if it is possible to interact with two arrays as such for unique values?
You are interested in listing all names out of $users which don't exist in $players or $recents, right?
Assuming you are only interested in the name:
// First, let's get a new array with all names from both arrays (can contain dups)
$pcNames = array_map($players + $recents, function($playerObject) {
return $playerObject->name;
});
// Next, let's remove all dups
$pcNames = array_unique($pcNames);
// === At this point you have an array with all names from `$players` and `$recents` ===
// === You may do something else with those, but I'll now create another array with ===
// === all users not in the players/recents lists. ===
// Now let's also get a list of names of users in the `$users` variable
$userNames = array_map($users, function($playerObject) {
return $playerObject->name;
});
// And finally let's get all names which are not in players or recents
$diffNames = array_diff($userNames, $pcNames);
// Let's output those to see whether it worked
var_dump($diffNames);
Of course there are other ways depending on your use case. We could for example extract the names of all three arrays and then just use array_diff with 3 arguments (but then you don't have the $pcArray side product), or if you actually want to compare IDs but print names, we would have to change all the inline functions to extract ID instead of name and further down reference the users array to get the actual name, etc.
I am trying to get some specific fields out of this Json.
fn({
"processingDurationMillis": 454,
"authorisedAPI": true,
"success": true,
"airline": "MH",
"validCreditCards": [
"AX",
"CA",
"VI"
],
"paypal": true,
"outboundOptions": [
{
"optionId": 0,
"flights": [
{
"flightNumber": "0066",
"departureAirport": {
"code": "KUL",
"name": "Kuala Lumpur Intl",
"city": "Kuala Lumpur",
"country": "Malaysia",
"timezone": "Asia/Kuala_Lumpur",
"lat": 2.745578,
"lng": 101.709917,
"terminal": null,
"gate": null
},
"arrivalAirport": {
"code": "ICN",
"name": "Incheon Intl",
"city": "Seoul",
"country": "South Korea",
"timezone": "Asia/Seoul",
"lat": 37.469075,
"lng": 126.450517,
"terminal": null,
"gate": null
},
"marketingAirline": "MH",
"mealIndicator": "M",
"allowedSsrs": {
},
"operatingAirline": null,
"equipment": "333",
"equipmentName": "Airbus A330-300",
"flightRPH": 10101,
"comments": [
"MH CODESHARE WITH KE"
],
"depScheduled": "2015-04-28T23:30:00.000+08:00",
"arrScheduled": "2015-04-29T07:10:00.000+09:00",
"depEstimated": null,
"depActual": null,
"arrEstimated": null,
"arrActual": null,
"eligibleForEticketing": true,
"cabin": "ECONOMY",
"fareMarketingType": "BASIC",
"rbd": "N",
"seatsAvailable": 9,
"durationMinutes": 400,
"minutesToScheduledFlightDeparture": 6486
}
],
"stopOvers": [
],
"fareDetails": {
"perPassengerJourneyFares": [
{
"passengerType": "ADT",
"fare": "1214.95",
"currencyCode": "MYR"
}
],
"perPassengerTripTaxes": [
{
"passengerType": "ADT",
"totalTax": "68.90",
"taxes": [
{
"code": "MY",
"amount": "65.00",
"currency": "MYR"
},
{
"code": "D8",
"amount": "3.90",
"currency": "MYR"
}
]
}
],
"journeyFare": "1214.95",
"totalTripFare": "1283.90",
"fareCurrency": "MYR"
},
"magicString": "2t2qi8oNXWkrDR75zYDrk9+3wNaJBzHyK1ftoR/VZPVgHO+EFTkh8DMg5WUl1ap7VjwBsnhD2gFxAwBbHhY0+k0lp7BUvSoYSKg6S6u4ZkvbIWMktl+lHgcKl46vht9//2dZVJvH4D7WJvnJTtK5O4TWNrkiTmEdHp55yRmjwWfsgNswOIMXoWrZj3OUJ4DH4POJ8rmfilimvtpBCdxNsqoZDVC9d6/6LiICZ3wHZJ7w/88QuExFV7OsHbc+jI3trRzDCCb6Ns62MGyfsXX6Pz8mJe6gs02UjapVSPa3M9CqLGMCN0xCF28WNbavhSI9jG3cWsQbxGU8rnhmjx00Iw5v2qqjdE/Dx432Qzs4s36SqUjLF7KN9hAJoQuMX3emE4gZ+7ANJ5bDTDEYZlnUZ4iXKykzUptYDyGay0evu1kdCjxPJlgiEtOl3hFMaKC+eoTsjps4RoYy0Z7oD3aP52qCYPdCH+8XTic522UKU1mW9HMjmGxH5zrvYK2rOgzSR2+xH5K3IpXHBAQqWOTEvmirP4qvg5VOPjyO9mIM83I6aY1JAkqo9jYqtEwrGqANdhA9z78EdoyQYKZBXcLsQMKz06fAczwk/WxxIi1ctL8EW+aZYddkbPo7xD6NWc8bJ+ARw5AlS1tirVNcO3mN5jVr/a6qftVuaz/0q83VsX4ztQpgMjDkptbw9Zz6DNLgiLJEzdf7fraoVUyzeth5wucOMzpLBP+ERbD7XFnDSKN8QzG6lLpDK8qy95K5FMmcF4uDq8Y1waTyIN9sS+v50OTbjr7Ebs3uKIxMZFfGUfp7YpDiVyo+2x4La4K7rhHPtoR6iEfVCjnTAUvamQu3qgL3vuSCPPPJiHFbdOrKVlp3kfAxaIcJpX3Z+Twx2cNAhsGHSk2ZazzvP5Pw1EF066VcoDkld9Oe/Qu5cC+DtG2LHhMA7NU8hMD66q9UCsXC6P/mjbKr7hatjHyyklDIKuxxirMpYkukEa73RJlhKmC0fjj4EYcgRy5MtybexuN59KaTeSEFxMGFIkv0zHp5jO/wHUvyypqbxTKFR3VAx6WpmSNg/Iui2uXDhNu/F4zJnYQUW9EyluZEPebFk2Uj455O2+y0UmFe4WnUY+0d92obZNv855/ctA4UC/LQn2s9azqdhDIeUUHuHEn2a4Grb+7l8wuai6ybBmmE62ck+CqMou+A+CUwk71KMkh3ZXf8BdeelW8Ia7r9ja7wKNBklgYo4Q8xOR63QhyCt2BiiR9aOxiDIKiW7bxSFCBga7yIPWx/NZdGjUYTuiJ9KZ7W2dKLhF6XDU5mWOV7XwMRzkyschEnjSzQWGjTTftEIiNI1V1M2bhFwc92JkfVFxwXCg==",
"seatsAvailable": [
9
],
"corporateAccount": false,
"flightCanBeHeld": true,
"durationMinutes": 400,
"gaFareDetails": {
"perPassengerJourneyFares": [
{
"passengerType": "ADT",
"fare": "1214.95",
"currencyCode": "MYR"
}
],
"perPassengerTripTaxes": [
{
"passengerType": "ADT",
"totalTax": "68.90",
"taxes": [
{
"code": "MY",
"amount": "65.00",
"currency": "MYR"
},
{
"code": "D8",
"amount": "3.90",
"currency": "MYR"
}
]
}
],
"journeyFare": "1214.95",
"totalTripFare": "1283.90",
"fareCurrency": "MYR"
},
"adobeFareDetails": {
"perPassengerJourneyFares": [
{
"passengerType": "ADT",
"fare": "336.66",
"currencyCode": "USD"
}
],
"perPassengerTripTaxes": [
{
"passengerType": "ADT",
"totalTax": "19.09",
"taxes": [
{
"code": "MY",
"amount": "18.01",
"currency": "USD"
},
{
"code": "D8",
"amount": "1.08",
"currency": "USD"
}
]
}
],
"journeyFare": "336.66",
"totalTripFare": "355.77",
"fareCurrency": "USD"
},
"userAgentFareDetails": {
"perPassengerJourneyFares": [
{
"passengerType": "ADT",
"fare": "336.66",
"currencyCode": "USD"
}
],
"perPassengerTripTaxes": [
{
"passengerType": "ADT",
"totalTax": "19.09",
"taxes": [
{
"code": "MY",
"amount": "18.01",
"currency": "USD"
},
{
"code": "D8",
"amount": "1.08",
"currency": "USD"
}
]
}
],
"journeyFare": "336.66",
"totalTripFare": "355.77",
"fareCurrency": "USD"
},
"eligibleForeTicketing": true,
"lowestSeatCount": 9,
"directFlight": true
}
],
"departureAirport": {
"code": "KUL",
"name": "Kuala Lumpur Intl",
"city": "Kuala Lumpur",
"country": "Malaysia",
"timezone": "Asia/Kuala_Lumpur",
"lat": 2.745578,
"lng": 101.709917,
"terminal": null,
"gate": null
},
"arrivalAirport": {
"code": "ICN",
"name": "Incheon Intl",
"city": "Seoul",
"country": "South Korea",
"timezone": "Asia/Seoul",
"lat": 37.469075,
"lng": 126.450517,
"terminal": null,
"gate": null
},
"apiRequired": true,
"fareRules": [
{
"id": 50,
"order": 1,
"priority": 0,
"code": "Basic",
"name": "MHbasic",
"value": "Economy Class Fares",
"listFareRules": [
{
"id": 130,
"order": 0,
"code": "",
"name": "Discount level",
"value": "Up to 65%"
},
{
"id": 140,
"order": 1,
"code": "",
"name": "Where to buy",
"value": "All channels"
},
{
"id": 150,
"order": 2,
"code": "",
"name": "Advance purchase",
"value": "Applies"
},
{
"id": 160,
"order": 3,
"code": "",
"name": "Payment",
"value": "Ticket dateline applies"
},
{
"id": 170,
"order": 4,
"code": "",
"name": "Baggage allowance",
"value": "2pc/30kg"
},
{
"id": 180,
"order": 5,
"code": "",
"name": "Advance seat selection",
"value": "Not allowed"
},
{
"id": 190,
"order": 6,
"code": "",
"name": "Enrich miles",
"value": "Nil"
},
{
"id": 200,
"order": 7,
"code": "",
"name": "Change of booking",
"value": "Not allowed"
},
{
"id": 210,
"order": 8,
"code": "",
"name": "Upgrade",
"value": "Not allowed"
},
{
"id": 220,
"order": 9,
"code": "",
"name": "Stand by at the airport",
"value": "For a fee"
},
{
"id": 220,
"order": 10,
"code": "",
"name": "No show",
"value": "Penalty applies"
},
{
"id": 230,
"order": 11,
"code": "",
"name": "Refund",
"value": "For a fee"
}
],
"listFareNotes": [
{
"id": 10,
"order": 0,
"code": "",
"name": "Important Notice",
"value": ""
},
{
"id": 15,
"order": 1,
"code": "",
"name": "",
"value": ""
},
{
"id": 20,
"order": 2,
"code": "",
"name": "1.",
"value": "Generic attributes shown only applies to MH operated flights. MH3000-3999, MH5200-5999 and MH9000-9999 Series flights are subject to their own rules. Please contact MH Call Center or ticket offices for actual fare rules."
},
{
"id": 30,
"order": 3,
"code": "",
"name": "2.",
"value": "For transpacific and transatlantic flights, the following baggage allowances apply: Economy - 2 pieces (23kg each piece), First and Business - 2 pieces (32kg each piece)."
},
{
"id": 50,
"order": 5,
"code": "",
"name": "3.",
"value": "Upgrade, standby at the airport and refund fees for specific routes can be obtained from subsequent booking pages."
},
{
"id": 60,
"order": 6,
"code": "",
"name": "4.",
"value": "Standby at the airport denotes the same day for an earlier flight."
},
{
"id": 70,
"order": 7,
"code": "",
"name": "5.",
"value": "Fare rules shown are indicative only. Please call our Contact Center to check the detailed fare rules."
},
{
"id": 80,
"order": 8,
"code": "",
"name": "",
"value": "Should there be any discrepancy between the above information and the terms and conditions (T&C) published in the fare rules, then the T&C in the fare rules shall prevail."
}
]
}
],
"Errors": [
],
"Warnings": [
]
})
i want extract flight number, depScheduled, arrScheduled and journey fare from the above json.
here are my code:
$json2 = json_decode($json,true);
$result= array();
foreach ($json2['outboundOptions']['flights']as $theentity) {
$result[] = $theentity['flightNumber'];
}
print_r($result);
The code above return me a error, "Invalid argument supplied for foreach()".I searched around, but still have not found the solution yet..
It is giving you that error because outboundOptions is an array of objects. What you want is to access the first object:
foreach ($json2['outboundOptions'][0]['flights']as $theentity) {
$result[] = $theentity['flightNumber'];
}
Also, remove the trailing comma (,) from your ] at the end as that causes invalid json.
You can check if your json is valid by going to jsonlint.com
Working Example
Update as per your comment
To get all the flights, change your foreach loop to this:
foreach ($json3['outboundOptions'] as $flight) {
foreach($flight['flights'] as $theentity) {
$result[] = $theentity['flightNumber'];
}
}
Example
remove the trailing ',' near the very end of your json.
change your code, add a [0] before ['flights']
$json2 = json_decode($json,TRUE);
$result= array();
foreach ($json2['outboundOptions'][0]['flights']as $theentity) {
$result[] = $theentity['flightNumber'];
}
print_r($result);