After making the authentication in sabre from php and make an inquiry about a flight, the response is a JSON string that I can not decipher, someone aid me, as I can show this readable string in php for my project.
part of the code, thanks for your help
object(SharedContext)#3 (1) {
["results":"SharedContext":private]=>
array(7) {
["SECURITY"]=>``
NULL
["origin"]=>
string(3) "MTR"
["destination"]=>
string(3) "BOG"
["departureDate"]=>
string(10) "2016-06-10"
["LeadPriceCalendar"]=>
object(stdClass)#6 (5) {
["status"]=>
string(8) "Complete"
["type"]=>
string(11) "Application"
["errorCode"]=>
string(20) "WARN.RAF.APPLICATION"
["timeStamp"]=>
string(25) "2016-06-03T22:04:40+00:00"
["message"]=>
string(21) "No results were found"
}
["InstaFlight"]=>
NULL
["BargainFinderMax"]=>
object(stdClass)#4 (2) {
["OTA_AirLowFareSearchRS"]=>
object(stdClass)#10 (11) {
["PricedItinCount"]=>
int(6)
["BrandedOneWayItinCount"]=>
int(0)
["SimpleOneWayItinCount"]=>
int(0)
["DepartedItinCount"]=>
int(0)
["SoldOutItinCount"]=>
int(0)
["AvailableItinCount"]=>
int(0)
["Version"]=>
string(5) "1.8.6"
["Success"]=>
object(stdClass)#11 (0) {
}
["Warnings"]=>
object(stdClass)#12 (1) {
["Warning"]=>
array(4) {
[0]=>
object(stdClass)#13 (5) {
["Type"]=>
string(12) "WORKERTHREAD"
["ShortText"]=>
string(19) "1750772809123328107"
["Code"]=>
string(13) "TRANSACTIONID"
["MessageClass"]=>
string(1) "I"
["content"]=>
string(0) ""
}
[1]=>
object(stdClass)#14 (5) {
["Type"]=>
string(6) "SERVER"
["ShortText"]=>
string(5) "27037"
["Code"]=>
string(9) "TTFHLC702"
["MessageClass"]=>
string(1) "I"
["content"]=>
string(0) ""
}
[2]=>
object(stdClass)#15 (5) {
["Type"]=>
string(7) "DEFAULT"
["ShortText"]=>
string(5) "13330"
["Code"]=>
string(6) "RULEID"
["MessageClass"]=>
string(1) "I"
["content"]=>
string(0) ""
}
[3]=>
object(stdClass)#16 (5) {
["Type"]=>
string(3) "DRE"
["ShortText"]=>
string(5) "13291"
["Code"]=>
string(6) "RULEID"
["MessageClass"]=>
string(1) "I"
["content"]=>
string(0) ""
}
}
}
["PricedItineraries"]=>
object(stdClass)#17 (1) {
["PricedItinerary"]=>
array(6) {
[0]=>
object(stdClass)#18 (5) {
["SequenceNumber"]=>
int(1)
["AirItinerary"]=>
object(stdClass)#19 (2) {
["DirectionInd"]=>
string(6) "OneWay"
["OriginDestinationOptions"]=>
object(stdClass)#20 (1) {
["OriginDestinationOption"]=>
array(1) {
[0]=>
object(stdClass)#21 (2) {
["ElapsedTime"]=>
int(76)
["FlightSegment"]=>
array(1) {
[0]=>
object(stdClass)#22 (15) {
["DepartureDateTime"]=>
string(19) "2016-06-10T08:38:00"
["ArrivalDateTime"]=>
string(19) "2016-06-10T09:54:00"
["StopQuantity"]=>
int(0)
["FlightNumber"]=>
string(4) "3193"
["ResBookDesigCode"]=>
string(1) "Q"
["ElapsedTime"]=>
int(76)
["DepartureAirport"]=>
object(stdClass)#23 (2) {
["LocationCode"]=>
string(3) "MTR"
["content"]=>
string(0) ""
}
["ArrivalAirport"]=>
object(stdClass)#24 (3) {
["LocationCode"]=>
string(3) "BOG"
["TerminalID"]=>
string(1) "1"
["content"]=>
string(0) ""
}
["OperatingAirline"]=>
object(stdClass)#25 (4) {
["CompanyShortName"]=>
string(26) "LAN COLOMBIA AIRLINES S.A."
["Code"]=>
string(2) "LA"
["FlightNumber"]=>
string(4) "3193"
["content"]=>
string(0) ""
}
["Equipment"]=>
array(1) {
[0]=>
object(stdClass)#26 (2) {
["AirEquipType"]=>
string(3) "320"
["content"]=>
string(0) ""
}
}
["MarketingAirline"]=>
object(stdClass)#27 (2) {
["Code"]=>
string(2) "LA"
["content"]=>
string(0) ""
}
["MarriageGrp"]=>
string(1) "O"
["DepartureTimeZone"]=>
object(stdClass)#28 (1) {
["GMTOffset"]=>
float(-5)
}
["ArrivalTimeZone"]=>
object(stdClass)#29 (1) {
["GMTOffset"]=>
float(-5)
}
["TPA_Extensions"]=>
object(stdClass)#30 (1) {
["eTicket"]=>
object(stdClass)#31 (1) {
["Ind"]=>
bool(true)
}
}
}
}
}
}
}
}
Related
I've google sheet with this data:
I'm pulling it from google drive with simple code:
$ranges = [
'Price_1'
];
$params = array(
'ranges' => $ranges
);
$response = $service->spreadsheets_values->batchGet($spreadsheetId, $params);
The response is a complicated object:
object(Google_Service_Sheets_BatchGetValuesResponse)#58 (8) { ["collection_key":protected]=> string(11) "valueRanges" ["spreadsheetId"]=> string(44) "1BQpKLuvlaVeGqIqoGUOynF9IZ5C3zK6gagZiRJO1UEU" ["valueRangesType":protected]=> string(32) "Google_Service_Sheets_ValueRange" ["valueRangesDataType":protected]=> string(5) "array" ["internal_gapi_mappings":protected]=> array(0) { } ["modelData":protected]=> array(0) { } ["processed":protected]=> array(0) { } ["valueRanges"]=> array(1) { [0]=> object(Google_Service_Sheets_ValueRange)#67 (7) { ["collection_key":protected]=> string(6) "values" ["majorDimension"]=> string(4) "ROWS" ["range"]=> string(14) "Price_1!E2:E74" ["values"]=> array(65) { [0]=> array(1) { [0]=> string(2) "28" } [1]=> array(1) { [0]=> string(2) "14" } [2]=> array(1) { [0]=> string(1) "0" } [3]=> array(0) { } [4]=> array(1) { [0]=> string(2) "55" } [5]=> array(1) { [0]=> string(2) "28" } [6]=> array(1) { [0]=> string(1) "0" } [7]=> array(0) { } [8]=> array(0) { } [9]=> array(0) { } [10]=> array(0) { } [11]=> array(0) { } [12]=> array(0) { } [13]=> array(0) { } [14]=> array(0) { } [15]=> array(0) { } [16]=> array(0) { } [17]=> array(0) { } [18]=> array(0) { } [19]=> array(0) { } [20]=> array(1) { [0]=> string(2) "59" } [21]=> array(1) { [0]=> string(2) "49" } [22]=> array(0) { } [23]=> array(1) { [0]=> string(2) "38" } [24]=> array(1) { [0]=> string(2) "38" } [25]=> array(0) { } [26]=> array(1) { [0]=> string(2) "37" } [27]=> array(1) { [0]=> string(2) "25" } [28]=> array(1) { [0]=> string(1) "0" } [29]=> array(0) { } [30]=> array(1) { [0]=> string(2) "79" } [31]=> array(1) { [0]=> string(2) "99" } [32]=> array(0) { } [33]=> array(1) { [0]=> string(2) "75" } [34]=> array(1) { [0]=> string(2) "99" } [35]=> array(0) { } [36]=> array(1) { [0]=> string(2) "79" } [37]=> array(1) { [0]=> string(2) "99" } [38]=> array(0) { } [39]=> array(1) { [0]=> string(3) "160" } [40]=> array(1) { [0]=> string(3) "190" } [41]=> array(0) { } [42]=> array(0) { } [43]=> array(0) { } [44]=> array(0) { } [45]=> array(0) { } [46]=> array(0) { } [47]=> array(0) { } [48]=> array(0) { } [49]=> array(0) { } [50]=> array(0) { } [51]=> array(0) { } [52]=> array(1) { [0]=> string(2) "33" } [53]=> array(0) { } [54]=> array(1) { [0]=> string(2) "59" } [55]=> array(1) { [0]=> string(2) "34" } [56]=> array(1) { [0]=> string(1) "0" } [57]=> array(0) { } [58]=> array(1) { [0]=> string(2) "29" } [59]=> array(1) { [0]=> string(2) "14" } [60]=> array(1) { [0]=> string(1) "0" } [61]=> array(0) { } [62]=> array(1) { [0]=> string(2) "37" } [63]=> array(1) { [0]=> string(2) "25" } [64]=> array(1) { [0]=> string(1) "0" } } ["internal_gapi_mappings":protected]=> array(0) { } ["modelData":protected]=> array(0) { } ["processed":protected]=> array(0) { } } } }
and var_dump($response->getValueRanges()[0]['values']); gives this result:
array(74) { [0]=> array(5) { [0]=> string(2) "ID" [1]=> string(10) "Ticket for" [2]=> string(9) "Excursion" [3]=> string(8) "Duration" [4]=> string(14) "Price (Brutto)" } [1]=> array(5) { [0]=> string(3) "01A" [1]=> string(13) "adult ( 12+ )" [2]=> string(9) "Catamaran" [3]=> string(2) "2h" [4]=> string(2) "28" } [2]=> array(5) { [0]=> string(3) "01B" [1]=> string(18) "child ( age 5-11 )" [2]=> string(9) "Catamaran" [3]=> string(2) "2h" [4]=> string(2) "14" } [3]=> array(5) { [0]=> string(3) "01C" [1]=> string(18) "toodler ( age 0-4)" [2]=> string(9) "Catamaran" [3]=> string(2) "2h" [4]=> string(1) "0" } [4]=> array(0) { } [5]=> array(5) { [0]=> string(3) "02A" [1]=> string(13) "adult, age 8+" [2]=> string(17) "Luxurt yacht trip" [3]=> string(2) "3h" [4]=> string(2) "55" } [6]=> array(5) { [0]=> string(3) "02B" [1]=> string(14) "child, age 3-7" [2]=> string(17) "Luxurt yacht trip" [3]=> string(2) "3h" [4]=> string(2) "28" } [7]=> array(5) { [0]=> string(3) "02C" [1]=> string(16) "toodler, age 0-2" [2]=> string(17) "Luxurt yacht trip" [3]=> string(2) "3h" [4]=> string(1) "0" } [8]=> array(0) { } [9]=> array(3) { [0]=> string(3) "03A" [1]=> string(0) "" [2]=> string(8) "Sailboat" } [10]=> array(3) { [0]=> string(3) "03B" [1]=> string(0) "" [2]=> string(8) "Sailboat" } [11]=> array(3) { [0]=> string(3) "03C" [1]=> string(0) "" [2]=> string(8) "Sailboat" } [12]=> array(0) { } [13]=> array(3) { [0]=> string(3) "04A" [1]=> string(0) "" [2]=> string(9) "Submarine" } [14]=> array(3) { [0]=> string(3) "04B" [1]=> string(0) "" [2]=> string(9) "Submarine" } [15]=> array(3) { [0]=> string(3) "04C" [1]=> string(0) "" [2]=> string(9) "Submarine" } [16]=> array(0) { } [17]=> array(3) { [0]=> string(3) "05A" [1]=> string(0) "" [2]=> string(13) "JetSki safari" } [18]=> array(3) { [0]=> string(3) "05B" [1]=> string(0) "" [2]=> string(13) "JetSki safari" } [19]=> array(3) { [0]=> string(3) "05C" [1]=> string(0) "" [2]=> string(13) "JetSki safari" } [20]=> array(0) { } [21]=> array(5) { [0]=> string(3) "06A" [1]=> string(9) "fisherman" [2]=> string(7) "Fishing" [3]=> string(2) "4h" [4]=> string(2) "59" } [22]=> array(5) { [0]=> string(3) "06B" [1]=> string(9) "spectator" [2]=> string(7) "Fishing" [3]=> string(2) "4h" [4]=> string(2) "49" } [23]=> array(0) { } [24]=> array(5) { [0]=> string(3) "07A" [1]=> string(5) "adult" [2]=> string(12) "Parascending" [3]=> string(5) "30min" [4]=> string(2) "38" } [25]=> array(5) { [0]=> string(3) "07B" [1]=> string(13) "child, age 6+" [2]=> string(12) "Parascending" [3]=> string(5) "30min" [4]=> string(2) "38" } [26]=> array(0) { } [27]=> array(5) { [0]=> string(3) "08A" [1]=> string(14) "adult, age 12+" [2]=> string(9) "Siam Park" [3]=> string(0) "" [4]=> string(2) "37" } [28]=> array(5) { [0]=> string(3) "08B" [1]=> string(15) "child, age 3-11" [2]=> string(9) "Siam Park" [3]=> string(0) "" [4]=> string(2) "25" } [29]=> array(5) { [0]=> string(3) "08C" [1]=> string(16) "toodler, age 0-1" [2]=> string(9) "Siam Park" [3]=> string(0) "" [4]=> string(1) "0" } [30]=> array(0) { } [31]=> array(5) { [0]=> string(3) "09A" [1]=> string(17) "flight from 800m." [2]=> string(18) "Paragliding tandem" [3]=> string(5) "15min" [4]=> string(2) "79" } [32]=> array(5) { [0]=> string(3) "09B" [1]=> string(18) "flight from 1000m." [2]=> string(18) "Paragliding tandem" [3]=> string(5) "25min" [4]=> string(2) "99" } [33]=> array(0) { } [34]=> array(5) { [0]=> string(3) "10A" [1]=> string(21) "Single (for 1 person)" [2]=> string(27) "Quad safari Forest explorer" [3]=> string(2) "3h" [4]=> string(2) "75" } [35]=> array(5) { [0]=> string(3) "10B" [1]=> string(22) "Double (for 2 persons)" [2]=> string(27) "Quad safari Forest explorer" [3]=> string(2) "3h" [4]=> string(2) "99" } [36]=> array(0) { } [37]=> array(5) { [0]=> string(3) "11A" [1]=> string(21) "Single (for 1 person)" [2]=> string(24) "Quad Safari - Teide tour" [3]=> string(2) "4h" [4]=> string(2) "79" } [38]=> array(5) { [0]=> string(3) "11B" [1]=> string(22) "Double (for 2 persons)" [2]=> string(24) "Quad Safari - Teide tour" [3]=> string(2) "4h" [4]=> string(2) "99" } [39]=> array(0) { } [40]=> array(5) { [0]=> string(3) "12A" [1]=> string(21) "Single (for 1 person)" [2]=> string(15) "Buggy adventure" [3]=> string(2) "3h" [4]=> string(3) "160" } [41]=> array(5) { [0]=> string(3) "12B" [1]=> string(22) "Double (for 2 persons)" [2]=> string(15) "Buggy adventure" [3]=> string(2) "3h" [4]=> string(3) "190" } [42]=> array(0) { } [43]=> array(3) { [0]=> string(3) "13A" [1]=> string(0) "" [2]=> string(8) "Trekking" } [44]=> array(3) { [0]=> string(3) "13B" [1]=> string(0) "" [2]=> string(8) "Trekking" } [45]=> array(3) { [0]=> string(3) "13C" [1]=> string(0) "" [2]=> string(8) "Trekking" } [46]=> array(0) { } [47]=> array(3) { [0]=> string(3) "14A" [1]=> string(0) "" [2]=> string(7) "Karting" } [48]=> array(3) { [0]=> string(3) "14B" [1]=> string(0) "" [2]=> string(7) "Karting" } [49]=> array(3) { [0]=> string(3) "14C" [1]=> string(0) "" [2]=> string(7) "Karting" } [50]=> array(0) { } [51]=> array(3) { [0]=> string(3) "15A" [1]=> string(0) "" [2]=> string(11) "Jungle park" } [52]=> array(3) { [0]=> string(3) "15B" [1]=> string(0) "" [2]=> string(11) "Jungle park" } [53]=> array(5) { [0]=> string(3) "15C" [1]=> string(0) "" [2]=> string(11) "Jungle park" [3]=> string(0) "" [4]=> string(2) "33" } [54]=> array(0) { } [55]=> array(5) { [0]=> string(3) "16A" [1]=> string(14) "adult, age 12+" [2]=> string(16) "La Gomera island" [3]=> string(12) "7:40 - 18:00" [4]=> string(2) "59" } [56]=> array(5) { [0]=> string(3) "16B" [1]=> string(15) "child, age 2-11" [2]=> string(16) "La Gomera island" [3]=> string(12) "7:40 - 18:00" [4]=> string(2) "34" } [57]=> array(5) { [0]=> string(3) "16C" [1]=> string(16) "toodler, age 0-1" [2]=> string(16) "La Gomera island" [3]=> string(12) "7:40 - 18:00" [4]=> string(1) "0" } [58]=> array(0) { } [59]=> array(5) { [0]=> string(3) "17A" [1]=> string(14) "adult, age 12+" [2]=> string(31) "Santa Cruz/ La Laguna/ Taganana" [3]=> string(1) "?" [4]=> string(2) "29" } [60]=> array(5) { [0]=> string(3) "17B" [1]=> string(15) "child, age 2-11" [2]=> string(31) "Santa Cruz/ La Laguna/ Taganana" [3]=> string(1) "?" [4]=> string(2) "14" } [61]=> array(5) { [0]=> string(3) "17C" [1]=> string(16) "toodler, age 0-1" [2]=> string(31) "Santa Cruz/ La Laguna/ Taganana" [3]=> string(1) "?" [4]=> string(1) "0" } [62]=> array(0) { } [63]=> array(5) { [0]=> string(3) "18A" [1]=> string(14) "adult, age 12+" [2]=> string(11) "Loro parque" [3]=> string(12) "8:30 - 18:45" [4]=> string(2) "37" } [64]=> array(5) { [0]=> string(3) "18B" [1]=> string(15) "child, age 6-11" [2]=> string(11) "Loro parque" [3]=> string(0) "" [4]=> string(2) "25" } [65]=> array(5) { [0]=> string(3) "18C" [1]=> string(16) "toodler, age 0-1" [2]=> string(11) "Loro parque" [3]=> string(0) "" [4]=> string(1) "0" } [66]=> array(0) { } [67]=> array(3) { [0]=> string(3) "19A" [1]=> string(0) "" [2]=> string(9) "Antologia" } [68]=> array(3) { [0]=> string(3) "19B" [1]=> string(0) "" [2]=> string(9) "Antologia" } [69]=> array(3) { [0]=> string(3) "19C" [1]=> string(0) "" [2]=> string(9) "Antologia" } [70]=> array(0) { } [71]=> array(3) { [0]=> string(3) "20A" [1]=> string(0) "" [2]=> string(13) "Medieval show" } [72]=> array(3) { [0]=> string(3) "20B" [1]=> string(0) "" [2]=> string(13) "Medieval show" } [73]=> array(3) { [0]=> string(3) "20C" [1]=> string(0) "" [2]=> string(13) "Medieval show" } }
And:
for($i = 1; $i < 5; $i++) {
print_r ($response->getValueRanges()[0]['values'][$i]);
}
Gives: Array ( [0] => 01A [1] => adult ( 12+ ) [2] => Catamaran [3] => 2h [4] => 28 ) Array ( [0] => 01B [1] => child ( age 5-11 ) [2] => Catamaran [3] => 2h [4] => 14 ) Array ( [0] => 01C [1] => toodler ( age 0-4) [2] => Catamaran [3] => 2h [4] => 0 ) Array ( )
In result I need a simple array, which will hold a key[row id], the ID from from ID row and price from last row, somethig like this: $result[$i] = unique_id=1, ID=01A, price=28
How it could be achieved?
So after getting the data for google sheet with:
$arr = $response->getValueRanges()[0]['values'];
You can use this simple for loop to get the data as you need:
// notice start from 1 to avoid the headers
for($i = 1; $i < count($arr); $i++) {
$res[$i] = array("unique_id" => $i, "ID" => $arr[$i][0], "price" => $arr[$i][4]);
}
Now $res will contain you structure.
Hi I have this huge array:
array(14) {
["imagen-profesor"]=>
array(8) {
["id"]=>
string(15) "imagen-profesor"
["slug"]=>
string(15) "imagen-profesor"
["type"]=>
string(5) "image"
["name"]=>
string(15) "Imagen profesor"
["description"]=>
string(17) "Foto del profesor"
["data"]=>
array(8) {
["slug-pre-save"]=>
string(15) "imagen-profesor"
["placeholder"]=>
string(0) ""
["user_default_value"]=>
string(0) ""
["repetitive"]=>
string(1) "0"
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
["validate"]=>
array(1) {
["url2"]=>
array(3) {
["active"]=>
string(1) "1"
["message"]=>
string(60) "Please enter a valid URL address pointing to the image file."
["suppress_for_cred"]=>
bool(true)
}
}
}
["meta_key"]=>
string(20) "wpcf-imagen-profesor"
["meta_type"]=>
string(8) "usermeta"
}
["grados-academicos"]=>
array(8) {
["id"]=>
string(17) "grados-academicos"
["slug"]=>
string(17) "grados-academicos"
["type"]=>
string(7) "wysiwyg"
["name"]=>
string(18) "Grados académicos"
["description"]=>
string(0) ""
["data"]=>
array(5) {
["slug-pre-save"]=>
string(17) "grados-academicos"
["user_default_value"]=>
string(0) ""
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(22) "wpcf-grados-academicos"
["meta_type"]=>
string(8) "usermeta"
}
["experiencia-profesional"]=>
array(8) {
["id"]=>
string(23) "experiencia-profesional"
["slug"]=>
string(23) "experiencia-profesional"
["type"]=>
string(7) "wysiwyg"
["name"]=>
string(23) "Experiencia profesional"
["description"]=>
string(46) "Por favor coloca aquí experiencia profesional"
["data"]=>
array(5) {
["slug-pre-save"]=>
string(23) "experiencia-profesional"
["user_default_value"]=>
string(0) ""
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(28) "wpcf-experiencia-profesional"
["meta_type"]=>
string(8) "usermeta"
}
["areas-de-interes"]=>
array(8) {
["id"]=>
string(16) "areas-de-interes"
["slug"]=>
string(16) "areas-de-interes"
["type"]=>
string(7) "wysiwyg"
["name"]=>
string(18) "Áreas de interés"
["description"]=>
string(22) "Intereses del profesor"
["data"]=>
array(5) {
["slug-pre-save"]=>
string(16) "areas-de-interes"
["user_default_value"]=>
string(0) ""
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(21) "wpcf-areas-de-interes"
["meta_type"]=>
string(8) "usermeta"
}
["cursos-relevantes"]=>
array(8) {
["id"]=>
string(17) "cursos-relevantes"
["slug"]=>
string(17) "cursos-relevantes"
["type"]=>
string(7) "wysiwyg"
["name"]=>
string(17) "Cursos relevantes"
["description"]=>
string(7) "Cursos "
["data"]=>
array(5) {
["slug-pre-save"]=>
string(17) "cursos-relevantes"
["user_default_value"]=>
string(0) ""
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(22) "wpcf-cursos-relevantes"
["meta_type"]=>
string(8) "usermeta"
}
["articulos"]=>
array(8) {
["id"]=>
string(9) "articulos"
["slug"]=>
string(9) "articulos"
["type"]=>
string(7) "wysiwyg"
["name"]=>
string(10) "Artículos"
["description"]=>
string(0) ""
["data"]=>
array(5) {
["slug-pre-save"]=>
string(9) "articulos"
["user_default_value"]=>
string(0) ""
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(14) "wpcf-articulos"
["meta_type"]=>
string(8) "usermeta"
}
["areas-academicas"]=>
array(8) {
["id"]=>
string(16) "areas-academicas"
["slug"]=>
string(16) "areas-academicas"
["type"]=>
string(6) "select"
["name"]=>
string(18) "Áreas académicas"
["description"]=>
string(0) ""
["data"]=>
array(6) {
["slug-pre-save"]=>
string(16) "areas-academicas"
["options"]=>
array(12) {
["wpcf-fields-select-option-96129381b0cc289dd28e00d98f8c15b0-1"]=>
array(2) {
["title"]=>
string(23) "Análisis de decisiones"
["value"]=>
string(1) "1"
}
["wpcf-fields-select-option-f320b41329b42d462bd08eb7961f2c65-1"]=>
array(2) {
["title"]=>
string(17) "Comercialización"
["value"]=>
string(1) "2"
}
["wpcf-fields-select-option-f6b63eb3926b7de2462225998e09cc13-1"]=>
array(2) {
["title"]=>
string(32) "Control e información directiva"
["value"]=>
string(1) "3"
}
["wpcf-fields-select-option-b2610684e6f824fd687a74d3be7bcabe-1"]=>
array(2) {
["title"]=>
string(21) "Dirección financiera"
["value"]=>
string(1) "4"
}
["wpcf-fields-select-option-d2c3f7b635105db769c4772a15d5cec2-1"]=>
array(2) {
["title"]=>
string(25) "Dirección de operaciones"
["value"]=>
string(1) "5"
}
["wpcf-fields-select-option-f14bad56bc815fa8060ae231ccb8a217-1"]=>
array(2) {
["title"]=>
string(22) "Dirección de personal"
["value"]=>
string(1) "6"
}
["wpcf-fields-select-option-c6114cc9883ef2a4c8d23d9985fd41fc-1"]=>
array(2) {
["title"]=>
string(15) "Empresa-familia"
["value"]=>
string(1) "7"
}
["wpcf-fields-select-option-6378fcaa75be017d5cddec1f4c837bba-1"]=>
array(2) {
["title"]=>
string(18) "Entorno económico"
["value"]=>
string(1) "8"
}
["wpcf-fields-select-option-48713712cd807bd0920369faaea72630-1"]=>
array(2) {
["title"]=>
string(26) "Entorno político y social"
["value"]=>
string(1) "9"
}
["wpcf-fields-select-option-35c50a5e264b2951ccbd9a83f0d52185-1"]=>
array(2) {
["title"]=>
string(13) "Factor humano"
["value"]=>
string(2) "10"
}
["wpcf-fields-select-option-bdac1a39ab699e74fbffd3b6a9aa85be-1"]=>
array(2) {
["title"]=>
string(20) "Política de empresa"
["value"]=>
string(2) "11"
}
["default"]=>
string(10) "no-default"
}
["validate"]=>
array(1) {
["required"]=>
array(3) {
["active"]=>
string(1) "1"
["value"]=>
string(4) "true"
["message"]=>
string(25) "Por favor, elige el área"
}
}
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(21) "wpcf-areas-academicas"
["meta_type"]=>
string(8) "usermeta"
}
["calendario"]=>
array(8) {
["id"]=>
string(10) "calendario"
["slug"]=>
string(10) "calendario"
["type"]=>
string(4) "date"
["name"]=>
string(10) "Calendario"
["description"]=>
string(0) ""
["data"]=>
array(7) {
["slug-pre-save"]=>
string(10) "calendario"
["placeholder"]=>
string(0) ""
["date_and_time"]=>
string(4) "date"
["repetitive"]=>
string(1) "0"
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(15) "wpcf-calendario"
["meta_type"]=>
string(8) "usermeta"
}
["duracion"]=>
array(8) {
["id"]=>
string(8) "duracion"
["slug"]=>
string(8) "duracion"
["type"]=>
string(8) "textarea"
["name"]=>
string(9) "Duración"
["description"]=>
string(0) ""
["data"]=>
array(7) {
["slug-pre-save"]=>
string(8) "duracion"
["placeholder"]=>
string(0) ""
["user_default_value"]=>
string(0) ""
["repetitive"]=>
string(1) "0"
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(13) "wpcf-duracion"
["meta_type"]=>
string(8) "usermeta"
}
["fechas"]=>
array(8) {
["id"]=>
string(6) "fechas"
["slug"]=>
string(6) "fechas"
["type"]=>
string(8) "textarea"
["name"]=>
string(6) "Fechas"
["description"]=>
string(0) ""
["data"]=>
array(7) {
["slug-pre-save"]=>
string(6) "fechas"
["placeholder"]=>
string(0) ""
["user_default_value"]=>
string(0) ""
["repetitive"]=>
string(1) "0"
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(11) "wpcf-fechas"
["meta_type"]=>
string(8) "usermeta"
}
["contacto"]=>
array(8) {
["id"]=>
string(8) "contacto"
["slug"]=>
string(8) "contacto"
["type"]=>
string(7) "wysiwyg"
["name"]=>
string(8) "Contacto"
["description"]=>
string(0) ""
["data"]=>
array(5) {
["slug-pre-save"]=>
string(8) "contacto"
["user_default_value"]=>
string(0) ""
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(13) "wpcf-contacto"
["meta_type"]=>
string(8) "usermeta"
}
["areas-academicas-2"]=>
array(8) {
["id"]=>
string(18) "areas-academicas-2"
["slug"]=>
string(18) "areas-academicas-2"
["type"]=>
string(6) "select"
["name"]=>
string(24) "Segunda área académica"
["description"]=>
string(0) ""
["data"]=>
array(5) {
["slug-pre-save"]=>
string(18) "areas-academicas-2"
["options"]=>
array(12) {
["wpcf-fields-select-option-a84588db3f03c2837345f94adfa18588-1"]=>
array(2) {
["title"]=>
string(23) "Análisis de decisiones"
["value"]=>
string(1) "1"
}
["wpcf-fields-select-option-5a20ef6e60591caaf5bec848cf43cec0-1"]=>
array(2) {
["title"]=>
string(17) "Comercialización"
["value"]=>
string(1) "2"
}
["wpcf-fields-select-option-3b00b7d1d1040c63c3512a7e52446443-1"]=>
array(2) {
["title"]=>
string(32) "Control e información directiva"
["value"]=>
string(1) "3"
}
["wpcf-fields-select-option-da90a64b9b2bf7becfbec27c9c4025da-1"]=>
array(2) {
["title"]=>
string(21) "Dirección financiera"
["value"]=>
string(1) "4"
}
["wpcf-fields-select-option-65c40a4ea4cde81d6fb7b5bbe1c73282-1"]=>
array(2) {
["title"]=>
string(25) "Dirección de operaciones"
["value"]=>
string(1) "5"
}
["wpcf-fields-select-option-3b7a56cdb15cef8028daf43082269339-1"]=>
array(2) {
["title"]=>
string(22) "Dirección de personal"
["value"]=>
string(1) "6"
}
["wpcf-fields-select-option-6eded9521556a27a4cf4465c82f0a203-1"]=>
array(2) {
["title"]=>
string(15) "Empresa-familia"
["value"]=>
string(1) "7"
}
["wpcf-fields-select-option-5102092609e13386bfadc0ed367591b7-1"]=>
array(2) {
["title"]=>
string(18) "Entorno económico"
["value"]=>
string(1) "8"
}
["wpcf-fields-select-option-e1aadcfe82cc3389a57288a85ed45ff6-1"]=>
array(2) {
["title"]=>
string(26) "Entorno político y social"
["value"]=>
string(1) "9"
}
["wpcf-fields-select-option-6440b6d9a60739b88dacaafae2bccaa9-1"]=>
array(2) {
["title"]=>
string(13) "Factor humano"
["value"]=>
string(2) "10"
}
["wpcf-fields-select-option-2d081231584de301011755851f93b246-1"]=>
array(2) {
["title"]=>
string(20) "Política de empresa"
["value"]=>
string(2) "11"
}
["default"]=>
string(10) "no-default"
}
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(23) "wpcf-areas-academicas-2"
["meta_type"]=>
string(8) "usermeta"
}
["cargo-profesor"]=>
array(8) {
["id"]=>
string(14) "cargo-profesor"
["slug"]=>
string(14) "cargo-profesor"
["type"]=>
string(6) "select"
["name"]=>
string(14) "Cargo Profesor"
["description"]=>
string(36) "Selecciona un cargo para el profesor"
["data"]=>
array(6) {
["slug-pre-save"]=>
string(14) "cargo-profesor"
["options"]=>
array(5) {
["wpcf-fields-select-option-2a9da69d4d39817ac2a4b687ac49dc27-1"]=>
array(2) {
["title"]=>
string(18) "Director del área"
["value"]=>
string(1) "4"
}
["wpcf-fields-select-option-b7ae4c59b346a60a6680338c9c44c456-1"]=>
array(2) {
["title"]=>
string(8) "Profesor"
["value"]=>
string(1) "1"
}
["wpcf-fields-select-option-51a473bf339e2669511accaa90983fb0-1"]=>
array(2) {
["title"]=>
string(17) "Profesor invitado"
["value"]=>
string(1) "2"
}
["wpcf-fields-select-option-734e5707d3253ded0bf0d972f1c56afe-1"]=>
array(2) {
["title"]=>
string(6) "Decano"
["value"]=>
string(1) "3"
}
["default"]=>
string(10) "no-default"
}
["validate"]=>
array(1) {
["required"]=>
array(3) {
["active"]=>
string(1) "1"
["value"]=>
string(4) "true"
["message"]=>
string(23) "This field is required."
}
}
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(19) "wpcf-cargo-profesor"
["meta_type"]=>
string(8) "usermeta"
}
["segundo-cargo"]=>
array(8) {
["id"]=>
string(13) "segundo-cargo"
["slug"]=>
string(13) "segundo-cargo"
["type"]=>
string(6) "select"
["name"]=>
string(13) "Segundo cargo"
["description"]=>
string(0) ""
["data"]=>
array(5) {
["slug-pre-save"]=>
string(13) "segundo-cargo"
["options"]=>
array(5) {
["wpcf-fields-select-option-30ef69a1ba17b84f26edcee1404746f4-1"]=>
array(2) {
["title"]=>
string(18) "Director del área"
["value"]=>
string(1) "1"
}
["wpcf-fields-select-option-8b8dbd4c42d2e4d61053f442e82a88be-1"]=>
array(2) {
["title"]=>
string(8) "Profesor"
["value"]=>
string(1) "2"
}
["wpcf-fields-select-option-862f1fbf0e317265cf544b754d6fa3f0-1"]=>
array(2) {
["title"]=>
string(17) "Profesor invitado"
["value"]=>
string(1) "3"
}
["wpcf-fields-select-option-d49829cdb8f8aaae8af93f30f220ca86-1"]=>
array(2) {
["title"]=>
string(6) "Decano"
["value"]=>
string(1) "4"
}
["default"]=>
string(10) "no-default"
}
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(18) "wpcf-segundo-cargo"
["meta_type"]=>
string(8) "usermeta"
}
}
I just want to get this value: Análisis de decisiones, Comercialización, Control e información directiva, Dirección financiera, "Dirección de operaciones, Dirección de personal, Empresa-familia, Entorno económico, Entorno político y social, Factor humano, Política de empresa.
I mean what is inside areas-academicas
I'm using nested foreach but nothing:
foreach ($un as $key => $value)
{
if ( $key === "areas-academicas" )
{
echo "Llave: " . $key . " => ";
//echo $value;
foreach ( $value as $key2 => $value2 )
{
echo "Llave2: " . $key2 . "<br />" . "valor2: " . $value2;
foreach ($value2 as $key3 => $value3)
{
echo "Llave3: " . $key3 . "<br />" . "valor3: " . $value3;
}
}
}
}
What could be an easy way to get those values? thanks.
If I don't messed up with your nesting this should work. If it doesn't just fix the path inside the foreach.
$data = array(...); // the array you posted
foreach ($data["areas-academicas"]["data"]["options"] as $area) {
echo $area["title"];
}
The bottom line is you can start the iteration from any level, you don't have to begin at the top necessarily.
Looking at the Array it appears that youre only interested in two of arrays at the top level:
$un["areas-academicas"]
$un["areas-academicas-2"]
Then you are looking for specific values, titles of the options of the data, in the nested structure underneath these two:
$un["areas-academicas"]['data']['options'][....]['title']
You can probably limit the iterations of your loop by using the uniform structure of these arrays. But I will assume you wish to loop through the top level array for keys containing "areas-academicas":
$titles = array();
foreach ($un as $key => $value){
if(strpos($key, 'areas-academicas') == false){ continue; }
foreach($value['data']['options'] as $val){
$titles[] = $val['title'];
}
}
This loop should collect all the option titles from the areas-academicas arrays but is reliant on the idea that the nested structure will be uniform for each instance of the areas-academicas key in the top level array. Hope this helps
My PHP function is returning a SimpleXML array like this:
array(1) { [0]=> object(SimpleXMLElement)#6 (18) { ["#attributes"]=> array(6) { ["thumbnailUrl"]=> string(47) "users/908/721/swagg_ma_blue/thumbnail-12612.jpg" ["default"]=> string(1) "1" ["name"]=> string(5) "_copy" ["color"]=> string(8) "0xBB9977" ["mood"]=> string(1) "3" ["species"]=> string(4) "stud" } ["head"]=> object(SimpleXMLElement)#5 (1) { ["#attributes"]=> array(4) { ["url"]=> string(51) "http://assets.zwinky.com/assets/stud/heads/01/head1" ["c"]=> string(8) "0xF2B38A" ["c2"]=> string(8) "0xffffff" ["z"]=> string(5) "33000" } } ["face"]=> object(SimpleXMLElement)#7 (1) { ["#attributes"]=> array(5) { ["url"]=> string(51) "http://assets.zwinky.com/assets/stud/faces/01/stud1" ["c"]=> string(8) "0xFFFFFF" ["displayName"]=> string(5) "stud1" ["z"]=> string(5) "34000" ["id"]=> string(8) "20017217" } } ["belt"]=> array(2) { [0]=> object(SimpleXMLElement)#8 (1) { ["#attributes"]=> array(6) { ["url"]=> string(64) "http://assets.zwinky.com/assets/store/zwinky/stud/belts/01/Vblt1" ["c"]=> string(8) "0x000000" ["c2"]=> string(8) "0xFFFFFF" ["displayName"]=> string(30) "Tough Love Belt ketamine-dolly" ["z"]=> string(5) "20100" ["id"]=> string(8) "20098984" } } [1]=> object(SimpleXMLElement)#20 (1) { ["#attributes"]=> array(5) { ["url"]=> string(76) "http://ak.ugc.zwinky.com/zwinky/fds/creations/791/402/z-justin/1441479408229" ["isUgc"]=> string(4) "true" ["displayName"]=> string(9) "My Design" ["z"]=> string(5) "20100" ["id"]=> string(8) "20081015" } } } ["midsection"]=> object(SimpleXMLElement)#9 (1) { ["#attributes"]=> array(2) { ["url"]=> string(55) "http://assets.zwinky.com/assets/stud/midsections/01/ms1" ["z"]=> string(4) "9000" } } ["leg"]=> object(SimpleXMLElement)#10 (1) { ["#attributes"]=> array(2) { ["url"]=> string(50) "http://assets.zwinky.com/assets/stud/legs/01/legs1" ["z"]=> string(5) "10000" } } ["hair"]=> object(SimpleXMLElement)#11 (1) { ["#attributes"]=> array(6) { ["url"]=> string(62) "http://assets.zwinky.com/assets/store/zwinky/stud/hair/01/Zhr8" ["c"]=> string(8) "0xD0C0B0" ["c2"]=> string(8) "0x000000" ["displayName"]=> string(7) "spiky 3" ["z"]=> string(5) "37000" ["id"]=> string(8) "20013196" } } ["shirt"]=> object(SimpleXMLElement)#12 (1) { ["#attributes"]=> array(5) { ["url"]=> string(63) "http://assets.zwinky.com/assets/store/zwinky/stud/tops/01/Vtop2" ["c"]=> string(8) "0x212121" ["displayName"]=> string(8) "tank top" ["z"]=> string(5) "21000" ["id"]=> string(8) "20012196" } } ["jacket"]=> object(SimpleXMLElement)#13 (1) { ["#attributes"]=> array(5) { ["url"]=> string(76) "http://ak.ugc.zwinky.com/zwinky/fds/creations/113/681/b4d_b0yy/1452451820582" ["isUgc"]=> string(4) "true" ["displayName"]=> string(4) "asdf" ["z"]=> string(5) "30000" ["id"]=> string(8) "20080934" } } ["bottom"]=> object(SimpleXMLElement)#14 (1) { ["#attributes"]=> array(6) { ["url"]=> string(67) "http://assets.zwinky.com/assets/store/zwinky/stud/bottoms/01/MXbm14" ["c"]=> string(8) "0xD6D6D6" ["c2"]=> string(8) "0xFFFFFF" ["displayName"]=> string(15) "Steampunk Pants" ["z"]=> string(5) "20000" ["id"]=> string(8) "20039549" } } ["electronic"]=> object(SimpleXMLElement)#15 (1) { ["#attributes"]=> array(5) { ["url"]=> string(64) "http://assets.zwinky.com/assets/store/zwinky/stud/misc/01/SDmis1" ["c"]=> string(8) "0x3366FF" ["displayName"]=> string(12) "game player2" ["z"]=> string(5) "45000" ["id"]=> string(8) "20017518" } } ["hat"]=> object(SimpleXMLElement)#16 (1) { ["#attributes"]=> array(5) { ["url"]=> string(49) "http://assets.zwinky.com/assets/stud/hats/01/hat6" ["c"]=> string(3) "0x0" ["displayName"]=> string(13) "baseball cap2" ["z"]=> string(5) "40000" ["id"]=> string(8) "20017403" } } ["earrings"]=> object(SimpleXMLElement)#17 (1) { ["#attributes"]=> array(4) { ["url"]=> string(52) "http://assets.zwinky.com/assets/stud/earrings/01/er2" ["displayName"]=> string(10) "gold hoops" ["z"]=> string(5) "39000" ["id"]=> string(8) "20017442" } } ["bracelet"]=> object(SimpleXMLElement)#18 (1) { ["#attributes"]=> array(6) { ["url"]=> string(67) "http://assets.zwinky.com/assets/store/zwinky/stud/bracelets/01/Zbr1" ["c"]=> string(8) "0xFFFFFF" ["c2"]=> string(8) "0xB5B5B5" ["displayName"]=> string(13) "Leather Cuffs" ["z"]=> string(5) "13000" ["id"]=> string(8) "20013217" } } ["necklace"]=> object(SimpleXMLElement)#19 (1) { ["#attributes"]=> array(5) { ["url"]=> string(68) "http://assets.zwinky.com/assets/store/zwinky/stud/necklaces/01/SDnk1" ["c"]=> string(8) "0xffffff" ["displayName"]=> string(14) "Snoop Necklace" ["z"]=> string(5) "23000" ["id"]=> string(8) "20012554" } } ["facialhair"]=> object(SimpleXMLElement)#21 (1) { ["#attributes"]=> array(5) { ["url"]=> string(69) "http://assets.zwinky.com/assets/store/zwinky/stud/facialhair/01/Vfhr1" ["c"]=> string(8) "0xffffff" ["displayName"]=> string(16) "Evil Cupid beard" ["z"]=> string(5) "38000" ["id"]=> string(8) "20012194" } } ["food"]=> object(SimpleXMLElement)#22 (1) { ["#attributes"]=> array(4) { ["url"]=> string(64) "http://assets.zwinky.com/assets/store/zwinky/stud/misc/01/HWmis7" ["displayName"]=> string(11) "mug w/steam" ["z"]=> string(5) "47000" ["id"]=> string(8) "20017604" } } ["facialdecorations"]=> object(SimpleXMLElement)#23 (1) { ["#attributes"]=> array(5) { ["url"]=> string(88) "http://ak.ugc.zwinky.com/zwinky/fds/creations/235/447/simsea-gdh0thtb1tzch/1426865152881" ["isUgc"]=> string(4) "true" ["displayName"]=> string(9) "My Design" ["z"]=> string(5) "42500" ["id"]=> string(8) "20081020" } } } }
My function looks like the following:
function get_user_outfit(){
$zwinky_login = $this->curl_post_login();
if($zwinky_login){
$user_outfit = $this->curl_post('http://outfits.zwinky.com/users/' . $this->user_directories() . '/outfits.xml', false, $this->cookie, true, false);
$xml = simplexml_load_string($user_outfit);
$element = $xml->xpath("//outfit[#default=1]");
return $element;
}else{
return 'Could not login.';
}
}
and I can't find a way to translate this into a string.
I've been trying the following http://php.net/manual/en/simplexmlelement.asxml.php which wouldnt work.
Does anyone have a idea?
$xml->xpath(...) returns an array of nodes of the type SimpleXMLElement.
There's built in functions to convert it to a string, although you'll have to loop through the returned nodes.
E.g.
$nodes = $xml->path(...);
$str = '';
foreach($nodes as $node){
$str .= $node->asXML();
}
return $str;
If you want the value of a node, you can invoke the magic method __toString on the SimpleXMLElement object. E.g. echo $node['attribute']; or echo $xml->path('//outfit[#default=1]/some/name')[0];
Alternatively use PHP DOM which gives you a lot more control and flexibility.
Since I stumbled over some wrong solutions (at least always pointing into the right direction) for having your instagram photos pulled onto my site, I started looking for new ways. And I had to implement SSL into the cURL scripting part to get the instagram feed.
However I am stuck in the following part: How can I tell my script to show my images?
I found out, that $result->data works, but if I continue this line with ->images PHP gives me the "Trying to get property of non-object". And the output of the decoded JSON is still lacking overviewability. I pasted here the code as far as I am right now, debugging mode.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.instagram.com/v1/users/myUserID/media/recent/?access_token=myAccessToken');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$result = curl_exec($ch);
curl_close($ch);
$result=json_decode($result);
$data=($result->data);
var_dump ($data->images);
// echo "<img src="$result->images->thumbnail->url">"
?>
Here is the output of the json_decode:
array(2) {
[0]=> object(stdClass)#4 (15) {
["attribution"]=> NULL
["tags"]=> array(4) {
[0]=> string(5) "remix"
[1]=> string(9) "trncfrmcn"
[2]=> string(4) "tygn"
[3]=> string(9) "mastering"
}
["type"]=> string(5) "image"
["location"]=> NULL
["comments"]=> object(stdClass)#5 (2) {
["count"]=> int(0)
["data"]=> array(0) { }
}
["filter"]=> string(7) "Toaster"
["created_time"]=> string(10) "1373149059"
["link"]=> string(34) "http://instagram.com/p/bcOOGMF5Vi/"
["likes"]=> object(stdClass)#6 (2) {
["count"]=> int(6)
["data"]=> array(4) {
[0]=> object(stdClass)#7 (4) {
["username"]=> string(13) "itsallaboutva"
["profile_picture"]=> string(77)
"http://images.ak.instagram.com/profiles/profile_186336970_75sq_1341852049.jpg"
["id"]=> string(9) "186336970"
["full_name"]=> string(16) "Victoria Anwuzia"
}
[1]=> object(stdClass)#8 (4) {
["username"]=> string(15) "eatmybeatsordie"
["profile_picture"]=> string(76)
"http://images.ak.instagram.com/profiles/profile_32709002_75sq_1355602472.jpg"
["id"]=> string(8) "32709002"
["full_name"]=> string(12) "D-Mite Beats"
}
[2]=> object(stdClass)#9 (4) {
["username"]=> string(12) "joetranmusic"
["profile_picture"]=> string(76) "http://images.ak.instagram.com/profiles/profile_32545994_75sq_1362449260.jpg"
["id"]=> string(8) "32545994"
["full_name"]=> string(8) "Joe Tran"
}
[3]=> object(stdClass)#10 (4) {
["username"]=> string(14) "xariahmarshall"
["profile_picture"]=> string(77) "http://images.ak.instagram.com/profiles/profile_275171230_75sq_1362937374.jpg"
["id"]=> string(9) "275171230"
["full_name"]=> string(14) "xariahmarshall"
}
}
}
["images"]=> object(stdClass)#11 (3) {
["low_resolution"]=> object(stdClass)#12 (3) {
["url"]=> string(79) "http://distilleryimage2.s3.amazonaws.com/ded954f8e68911e2adc122000a1f9ace_6.jpg"
["width"]=> int(306)
["height"]=> int(306)
}
["thumbnail"]=> object(stdClass)#13 (3) {
["url"]=> string(79) "http://distilleryimage2.s3.amazonaws.com/ded954f8e68911e2adc122000a1f9ace_5.jpg"
["width"]=> int(150)
["height"]=> int(150)
}
["standard_resolution"]=> object(stdClass)#14 (3) {
["url"]=> string(79) "http://distilleryimage2.s3.amazonaws.com/ded954f8e68911e2adc122000a1f9ace_7.jpg"
["width"]=> int(612)
["height"]=> int(612)
}
}
["users_in_photo"]=> array(0) { }
["caption"]=> object(stdClass)#15 (4) {
["created_time"]=> string(10) "1373149155"
["text"]=> string(34) "#Mastering #TYGN #TRNCFRMCN #Remix"
["from"]=> object(stdClass)#16 (4) {
["username"]=> string(12) "liebdich9vol"
["profile_picture"]=> string(77) "http://images.ak.instagram.com/profiles/profile_444541508_75sq_1372633384.jpg"
["id"]=> string(9) "444541508"
["full_name"]=> string(11) "Ian Maybach"
}
["id"]=> string(18) "494333402642093342"
}
["user_has_liked"]=> bool(false)
["id"]=> string(28) "494332600473064802_444541508"
["user"]=> object(stdClass)#17 (6) {
["username"]=> string(12) "liebdich9vol"
["website"]=> string(0) ""
["profile_picture"]=> string(77) "http://images.ak.instagram.com/profiles/profile_444541508_75sq_1372633384.jpg"
["full_name"]=> string(11) "Ian Maybach"
["bio"]=> string(0) ""
["id"]=> string(9) "444541508"
}
}
[1]=> object(stdClass)#18 (15) {
["attribution"]=> NULL
["tags"]=> array(3) {
[0]=> string(6) "studio"
[1]=> string(6) "garden"
[2]=> string(4) "view"
}
["type"]=> string(5) "image"
["location"]=> NULL
["comments"]=> object(stdClass)#19 (2) {
["count"]=> int(0)
["data"]=> array(0) { }
}
["filter"]=> string(7) "Toaster"
["created_time"]=> string(10) "1372661045"
["link"]=> string(34) "http://instagram.com/p/bNrZ-sl5Xp/"
["likes"]=> object(stdClass)#20 (2) {
["count"]=> int(4)
["data"]=> array(4) {
[0]=> object(stdClass)#21 (4) {
["username"]=> string(9) "seanbabas"
["profile_picture"]=> string(76) "http://images.ak.instagram.com/profiles/profile_30025104_75sq_1369077409.jpg"
["id"]=> string(8) "30025104"
["full_name"]=> string(10) "Sean Babas"
}
[1]=> object(stdClass)#22 (4) {
["username"]=> string(12) "ginocolletti"
["profile_picture"]=> string(75) "http://images.ak.instagram.com/profiles/profile_4634400_75sq_1364847565.jpg"
["id"]=> string(7) "4634400"
["full_name"]=> string(13) "Gino Colletti"
}
[2]=> object(stdClass)#23 (4) {
["username"]=> string(13) "marygraceklee"
["profile_picture"]=> string(75) "http://images.ak.instagram.com/profiles/profile_3269702_75sq_1373251095.jpg"
["id"]=> string(7) "3269702"
["full_name"]=> string(13) "Marygrace Lee"
}
[3]=> object(stdClass)#24 (4) {
["username"]=> string(10) "cyonthefly"
["profile_picture"]=> string(77) "http://images.ak.instagram.com/profiles/profile_225204950_75sq_1368426695.jpg"
["id"]=> string(9) "225204950"
["full_name"]=> string(21) "!CY ÊŽlÉŸÇɥʇuo ✈"
}
}
}
["images"]=> object(stdClass)#25 (3) {
["low_resolution"]=> object(stdClass)#26 (3) {
["url"]=> string(79) "http://distilleryimage9.s3.amazonaws.com/9f5f0300e21911e2929322000a9e0719_6.jpg"
["width"]=> int(306)
["height"]=> int(306)
}
["thumbnail"]=> object(stdClass)#27 (3) {
["url"]=> string(79) "http://distilleryimage9.s3.amazonaws.com/9f5f0300e21911e2929322000a9e0719_5.jpg"
["width"]=> int(150)
["height"]=> int(150)
}
["standard_resolution"]=> object(stdClass)#28 (3) {
["url"]=> string(79) "http://distilleryimage9.s3.amazonaws.com/9f5f0300e21911e2929322000a9e0719_7.jpg"
["width"]=> int(612)
["height"]=> int(612)
}
}
["users_in_photo"]=> array(0) { }
["caption"]=> object(stdClass)#29 (4) {
["created_time"]=> string(10) "1372900093"
["text"]=> string(21) "#studio #view #garden"
["from"]=> object(stdClass)#30 (4) {
["username"]=> string(12) "liebdich9vol"
["profile_picture"]=> string(77) "http://images.ak.instagram.com/profiles/profile_444541508_75sq_1372633384.jpg"
["id"]=> string(9) "444541508"
["full_name"]=> string(11) "Ian Maybach"
}
["id"]=> string(18) "492244118468531915"
}
["user_has_liked"]=> bool(false)
["id"]=> string(28) "490238835760272873_444541508"
["user"]=> object(stdClass)#31 (6) {
["username"]=> string(12) "liebdich9vol"
["website"]=> string(0) ""
["profile_picture"]=> string(77) "http://images.ak.instagram.com/profiles/profile_444541508_75sq_1372633384.jpg"
["full_name"]=> string(11) "Ian Maybach"
["bio"]=> string(0) ""
["id"]=> string(9) "444541508"
}
}
}
My aim is to have only one picture on my site but navigation arrows to switch to the next one. How would that be achieved?
To access infos from StdClass you can do this:
foreach($data->images as $i){
$i->url;
}
You can force a casting to array too:
foreach($data->images as $i){
$i = $i->toArray();
$i['url'];
}
And you can get the json decode on array form:
$data = json_decode($json,true); //the second param true means, bring me it like array.
as per http://php.net/json_decode, you need to specify you want an associative array instead of an object from json_decode:
so use json decode like this
$result=json_decode($result, true);
Now you will get array and you can easily access data.
Given the array below, how do I get values of object(stdClass) such as Pcv (campus Aalst), Mss ( Privaatpraktijk kinesitherapie Peeters Stefaan ), and so on?
array(106) {
[0]=>
object(stdClass)#8 (45) {
["nid"]=>
string(3) "199"
["type"]=>
string(11) "stageplaats"
["language"]=>
string(2) "nl"
["uid"]=>
string(2) "33"
["status"]=>
string(1) "1"
["created"]=>
string(10) "1291279334"
["changed"]=>
string(10) "1301323146"
["comment"]=>
string(1) "0"
["promote"]=>
string(1) "0"
["moderate"]=>
string(1) "0"
["sticky"]=>
string(1) "0"
["tnid"]=>
string(1) "0"
["translate"]=>
string(1) "0"
["vid"]=>
string(3) "206"
["revision_uid"]=>
string(2) "16"
["title"]=>
string(18) "Pcv (campus Aalst)"
["body"]=>
string(0) ""
["teaser"]=>
string(0) ""
["log"]=>
string(0) ""
["revision_timestamp"]=>
string(10) "1301323146"
["format"]=>
string(1) "0"
["nd_switch_bm"]=>
string(0) ""
["name"]=>
string(12) "stage.revaki"
["picture"]=>
string(0) ""
["data"]=>
string(72) "a:1:{s:13:"form_build_id";s:37:"form-f89b99e4a5249b192ff472579b826b00";}"
["field_stagedomein_audiologo"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_stagedomein_geneeskunde"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_stagedomein_lo"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_stagedomein_revaki"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(3) "152"
}
}
["field_stagedomein_verpleeg"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_status"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(14) "niet opgegeven"
}
}
["field_status_datum"]=>
array(1) {
[0]=>
array(4) {
["value"]=>
NULL
["timezone"]=>
string(15) "Europe/Brussels"
["timezone_db"]=>
string(15) "Europe/Brussels"
["date_type"]=>
string(4) "date"
}
}
["field_locatieview"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
string(3) "179"
}
}
["field_status_extra"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_status_stagedomein"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(6) "Actief"
}
}
["field_maxcapstud_stagedomein"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(2) "18"
}
}
["field_status_bevestigd_door"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
NULL
}
}
["field_aanpers_stageplaats"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
NULL
}
}
["field_extrainfo_stagedomein"]=>
array(1) {
[0]=>
array(2) {
["value"]=>
string(37) "Capaciteit: 3 studenten alle periodes"
["format"]=>
NULL
}
}
["field_percapaciteit_stageplaats"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_aanplaats_stageplaats"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_mentoren"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
string(3) "178"
}
}
["field_persoon_stagedomein"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
NULL
}
}
["has_body"]=>
string(1) "0"
["taxonomy"]=>
array(0) {
}
}
[1]=>
object(stdClass)#24 (45) {
["nid"]=>
string(3) "211"
["type"]=>
string(11) "stageplaats"
["language"]=>
string(2) "nl"
["uid"]=>
string(2) "33"
["status"]=>
string(1) "1"
["created"]=>
string(10) "1291281467"
["changed"]=>
string(10) "1301323440"
["comment"]=>
string(1) "0"
["promote"]=>
string(1) "0"
["moderate"]=>
string(1) "0"
["sticky"]=>
string(1) "0"
["tnid"]=>
string(1) "0"
["translate"]=>
string(1) "0"
["vid"]=>
string(3) "218"
["revision_uid"]=>
string(2) "16"
["title"]=>
string(53) "Mss ( Privaatpraktijk kinesitherapie Walravens Marc )"
["body"]=>
string(0) ""
["teaser"]=>
string(0) ""
["log"]=>
string(0) ""
["revision_timestamp"]=>
string(10) "1301323440"
["format"]=>
string(1) "0"
["nd_switch_bm"]=>
string(0) ""
["name"]=>
string(12) "stage.revaki"
["picture"]=>
string(0) ""
["data"]=>
string(72) "a:1:{s:13:"form_build_id";s:37:"form-f89b99e4a5249b192ff472579b826b00";}"
["field_stagedomein_audiologo"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_stagedomein_geneeskunde"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_stagedomein_lo"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_stagedomein_revaki"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(3) "128"
}
}
["field_stagedomein_verpleeg"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_status"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(14) "niet opgegeven"
}
}
["field_status_datum"]=>
array(1) {
[0]=>
array(4) {
["value"]=>
NULL
["timezone"]=>
string(15) "Europe/Brussels"
["timezone_db"]=>
string(15) "Europe/Brussels"
["date_type"]=>
string(4) "date"
}
}
["field_locatieview"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
string(3) "210"
}
}
["field_status_extra"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_status_stagedomein"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(6) "Actief"
}
}
["field_maxcapstud_stagedomein"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(1) "4"
}
}
["field_status_bevestigd_door"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
NULL
}
}
["field_aanpers_stageplaats"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
NULL
}
}
["field_extrainfo_stagedomein"]=>
array(1) {
[0]=>
array(2) {
["value"]=>
string(40) "Capaciteit: 1 student in periode 3 tem 6"
["format"]=>
NULL
}
}
["field_percapaciteit_stageplaats"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_aanplaats_stageplaats"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_mentoren"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
string(3) "208"
}
}
["field_persoon_stagedomein"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
NULL
}
}
["has_body"]=>
string(1) "0"
["taxonomy"]=>
array(0) {
}
}
[2]=>
object(stdClass)#26 (45) {
["nid"]=>
string(3) "217"
["type"]=>
string(11) "stageplaats"
["language"]=>
string(2) "nl"
["uid"]=>
string(2) "33"
["status"]=>
string(1) "1"
["created"]=>
string(10) "1291281906"
["changed"]=>
string(10) "1301323440"
["comment"]=>
string(1) "0"
["promote"]=>
string(1) "0"
["moderate"]=>
string(1) "0"
["sticky"]=>
string(1) "0"
["tnid"]=>
string(1) "0"
["translate"]=>
string(1) "0"
["vid"]=>
string(3) "224"
["revision_uid"]=>
string(2) "16"
["title"]=>
string(54) "Mss ( Privaatpraktijk kinesitherapie Peeters Stefaan )"
["body"]=>
string(0) ""
["teaser"]=>
string(0) ""
["log"]=>
string(0) ""
["revision_timestamp"]=>
string(10) "1301323440"
["format"]=>
string(1) "0"
["nd_switch_bm"]=>
string(0) ""
["name"]=>
string(12) "stage.revaki"
["picture"]=>
string(0) ""
["data"]=>
string(72) "a:1:{s:13:"form_build_id";s:37:"form-f89b99e4a5249b192ff472579b826b00";}"
["field_stagedomein_audiologo"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_stagedomein_geneeskunde"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_stagedomein_lo"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
The object is at the index 0 in the array, so you just access the property names from there
echo $theArray[0]->title;
For more information, please see the PHP manual's Language Reference, especially
the chapter on Arrays and
the chapter on Objects