An API I use sent me back an object/array (not sure).
this is the info i get back using print_out($arr):
Array
(
[0] => Array
(
[callID] => 40
[PairCallLegId] =>
[CallsCount] => 4
[LocalName] => 151204
[RemoteName] => 15740
[type] => 1
[isOut] => 0
[FirstName] => Boris
[lastName] => Ostrovsky
[AvgMos] => 3.7432666239999963
[AvgQoe] =>
[AvgPL] =>
[AvgJitter] =>
[AvgVideoQP] =>
[AvgBDW] => 1200
[AvgFrameRate] =>
[AvgTotalPkt] => 102433.80945757998
[AvgTotalBytes] =>
)
)
Im trying to reach the value inside "CallsCount" (should be 4)
I tried to use
$arr[0]["CallsCount"]
and
$arr["0"]["CallsCount"]
and even
$arr[0]->CallsCount
None works. i get Internal Server Error (500) every time.
What should i do?
Related
This question already has answers here:
How to get protected property of object in PHP
(8 answers)
Closed 3 years ago.
I am working with an api which answers the requests with "protected" data object
like this
(
[id:protected] => id:NYhXwGRVDzAAAAAAAAAA62
[name:protected] => 5cf8cdd54328c.EDF
[rev:protected] => 014a0000000150eaacf0
[size:protected] => 25136208
[server_modified:protected] => 2019-06-06T08:25:00Z
[has_explicit_shared_members:protected] =>
[data:protected] => Array
(
[name] => 5cf8cdd54328c.EDF
[path_lower] => /5cf8cdd54328c.edf
[path_display] => /5cf8cdd54328c.EDF
[id] => id:NYhXwGRVDzAAAAAAAA125
[client_modified] => 2019-06-06T08:25:00Z
[server_modified] => 2019-06-06T08:25:00Z
[rev] => 014a0000000150eaacf0
[size] => 25136208
[is_downloadable] => 1
[content_hash] => 86442139304784e3b18d1d46f1b20bc48847
)
)
I have converted the object to array with the following code
$metadata = (array)$file->getMetadata();
Array
(
[*id] => id:NYhXwGRVDzAAAAAA44554
[*name] => 5cf8cdd54328c.EDF
[*rev] => 014a0000000150eaacf0
[*size] => 25136208
[*media_info] =>
[*sharing_info] =>
[*path_display] => /5cf8cdd54328c.EDF
[*client_modified] => 2019-06-06T08:25:00Z
[*server_modified] => 2019-06-06T08:25:00Z
[*data] => Array
(
[name] => 5cf8cdd54328c.EDF
[path_display] => /5cf8cdd54328c.EDF
[id] => id:NYhXwGRVDzAAAAAAA23382
[client_modified] => 2019-06-06T08:25:00Z
[server_modified] => 2019-06-06T08:25:00Z
[rev] => 014a0000000150eaacf0
[size] => 25136208
[is_downloadable] => 1
[content_hash] => 86442139304784e3b18d1d46f1b20bc4884
)
)
But when i try to print the value print_r($metadata['*size']);
Notice: Undefined index: *size in C:\xampp\htdocs\Proyectos\kardion\kardion\sistema\download.php on line 28
I think it will be a very easy answer but I have no idea how to do it
I'm unsure where all those asterisks are coming from. I can't see them documented in any of the PHP ::getMetadata functions. Is this something you wrote yourself? I would suggest trying to remove any *s before attempting to read the index, and I suspect that's what's causing your error. Have you tried just print_r($metadata['size']);?
I am trying to access a multi-dimensional array using PHP. I can access the first level using -
$response['id']
but having trouble with how the second level is defined so I can do -
$response['first level']['second level']
Here is my json response -
Array
(
[id] => 7181676
[api_request_id] => 20984853
[user] => 8305
[vin] => JTDKN3DU7D1643423
[make] => Toyota
[model_name] => Prius
[model_year] => 2013
[last_updated] => 2019-02-22T01:08:15.628318Z
[recall_count] => 1
[status] => ok
[recalls] => Array
(
[0] => Array
(
[recall_id] => 15753
[recall_last_updated] => 2019-02-22T00:33:07.663232Z
[recall_age] => 0
[nhtsa_id] => 18V684000
[oem_id] => J0V
[name] => HybridSystem
[description] => CollisionRisk
[campaign_type] => nhtsa
[is_remedy_available] => 1
[are_parts_available] => 1
[risk_type] => collision
[risk_rank] => 5
[profit_rank] => 3
[overall_rank] => 5
[labor_difficulty] => 3
[government_id] => 18V684000
[is_reviewed] => 1
[child] => Array
(
)
)
)
)
How would I get lets say -
$response['profit_rank']
I am using the CakePHP framework. When returning the results of a query, the framework calls the "experimental" PDOStatement::getColumnMeta to "arrayify" the data when it comes back from the database. However, there are mixed results depending on the query.
There are times when the array of data comes back as expected where all columns are associated to the name of the view. Other times, the data comes back mixed, where some of the data sits in an array associated with the original table that corresponds to the view.
// correct
Array(
[MyInstall] => Array
(
[id] => a6d1342a-7b4d-11e1-8397-60195b7d6275
[user_id] => dc038c9e-7b4b-11e1-8397-60195b7d6275
[script_id] => 057de1e0-7b48-11e1-8397-60195b7d6275
[path] =>
[url] =>
[created] => 2009-06-15 12:43:30
[version] => 3.2.1
[admin_url] => wp-admin
[name] => WordPress
[icon] => icon_WordPress.gif
)
)
//incorrect
Array(
[MyInstall] => Array
(
[id] => c71a2368-7b4d-11e1-8397-60195b7d6275
[user_id] => dc038c9e-7b4b-11e1-8397-60195b7d6275
[path] =>
[url] =>
[created] => 2011-11-07 22:26:38
[version] => 3.2.1
[admin_url] => wp-admin
)
[Script] => Array
(
[script_id] => 057de1e0-7b48-11e1-8397-60195b7d6275
[name] => WordPress
[icon] => icon_WordPress.gif
)
)
The way the results are built is from the results of the PDOStatment::getColumnMeta. Here is what a sample result of getColumnMeta looks like:
Array
(
[native_type] => STRING
[pdo_type] => 2
[flags] => Array
(
[0] => not_null
)
[table] => MyInstall
[name] => id
[len] => 108
[precision] => 0
)
Any suggestions on how I can get this same information using PDO for MySQL? Or is there another solution to this problem?
BTW: I already filed a bug with the PHP folks on this.
As it turns out, this is a now known bug in MySQL: http://bugs.mysql.com/bug.php?id=66794, still pending at the time of writing.
Array
(
[0] => Array
(
[faq_id] => 14
[faq_faqcat_id] => 3
[faq_order] => 8
[faq_subject] => 800018
[faq_content] => 800019
[faq_datecreated] => 1213382678
[faq_dateupdated] => 1215547984
[faq_views] => 22
)
[1] => Array
(
[faq_id] => 15
[faq_faqcat_id] => 3
[faq_order] => 9
[faq_subject] => 800020
[faq_content] => 800021
[faq_datecreated] => 1213382698
[faq_dateupdated] => 1215547986
[faq_views] => 13
)
[2] => Array
(
[faq_id] => 16
[faq_faqcat_id] => 3
[faq_order] => 10
[faq_subject] => 800022
[faq_content] => 800023
[faq_datecreated] => 1213382711
[faq_dateupdated] => 1215547988
[faq_views] => 15
)
)
The above data is output of a PHP script. I have to convert this to a JSON object and show on an iPhone. can anyone please tell how?
Take a look at the json_encode and json_decode functions
For the parsing part on iOS you can use the native NSJSONSerialization class.
Dunno about iOS side, but from PHP it's pretty simple
http://php.net/manual/en/function.json-encode.php
echo json_encode($myArray);
Another SOAP question - I have a large multidimensional array, which echo's out fine when using print_r (eg you can see all of the data). The problem arises when I use
SOAPClient->__soapCall('Function', array('paramaters' => $feedUpload));
This actually returns an xml that looks like this: (using __getLastRequest)
<soap-env:envelope xmlns:ns1="http://www.property24.com/prosol/P24Feed" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:body>
<ns1:uploadlistings>
<ns1:feedupload>
<ns1:version>1</ns1:version>
<ns1:usertoken>
<ns1:token>3c7b39ea-c10b-451f-95bf-5118d84fb089</ns1:token>
</ns1:usertoken>
<ns1:command>UPLOAD</ns1:command>
<ns1:compress>None</ns1:compress>
<ns1:listings>
<ns1:listing>
<ns1:listingnumber>361000001</ns1:listingnumber>
<ns1:propertycategory>SR</ns1:propertycategory>
<ns1:listingdata>Array</ns1:listingdata>
<ns1:listingtype>A</ns1:listingtype>
</ns1:listing>
</ns1:listings>
</ns1:feedupload>
</ns1:uploadlistings>
</soap-env:body>
</soap-env:envelope>
As you can see, for ListingData it returns "Array". Here is the array schema:
Array
(
[parameters] => Array
(
[FeedUpload] => Array
(
[Version] => 1
[UserToken] => Array
(
[Token] => 5ece25e7-77d9-4dbf-8b8f-e047759ab8f4
)
[Command] => UPLOAD
[Compress] => None
[Listings] => Array
(
[Listing] => Array
(
[PropertyCategory] => SR
[ListingNumber] => 361000001
[ListingType] => A
[ListingData] => Array
(
[MandateDetails] => Array
(
[ListingNumber] => 361000001
[ListingType] => A
[MandateType] => O
[ClosedUserGroup] => C
[MarketCode] => A
[ListPrice] => 111000
[OccupationDate] =>
[OffMarketDate] =>
[OnMarketSince] =>
[ExpiryDate] => 2011-07-13T09:56:14Z
[ListDate] => 2011-07-13T09:51:14Z
[UpdateDate] => 2011-07-13T09:51:14Z
[VirtualTourUrl] =>
[ActualDirections] =>
[ShowHouseDirection] =>
[ViewComments] =>
[InternetComments] => Excellent stand situated on the flood plane with large riverine trees and great mountain views. The estate is situated along the world renowned Blyde River and is 394 ha in extent with only 154 sites on 4000 square metres. The estate has an array of plains game such as antelope, giraffe and wildebeest as well as hippo and crocodile. The riverine flood plain provides great birding opportunities such as the Pels fishing owl. There is a restaurant and clubhouse that serves meals and cocktails and offers
)
[PropertyDetails] => Array
(
[PropertyCategory] => SR
[PropertyType] => SRX
[Status] => ACTV
[Province] => Eastern Cape
[Town] => Aberdeen
[Suburb] => Balvinie
[StreetName] => Test Street
[StreetNumber] => 5
[PostalCode] => 0123
[ErfSize] => 1200
[HouseSize] =>
[Age] =>
[OwnerType] => G
[VATRegistered] => false
[MunicipalRatesAndTaxes] => 0
[MunicipalImprovementsValue] => 0
[MunicipalLandValue] => 0
[MunicipalTotalValue] => 0
[StandNumber] =>
[StandNumberSubdivided] =>
[PortionNumber] =>
[OwnerShipType] =>
)
[ResidentialDetails] => Array
(
[NoOfBathrooms] => 2
[BathroomDescription] =>
[NoOfBedrooms] => 6
[BedroomDescription] =>
[NoOfKitchens] => 2
[KitchenDescription] =>
[NoOfReceptionRooms] => 2
[ReceptionRoomDescription] =>
[NoOfStudies] => 1
[StudiesDescription] =>
[NoOfDomesticBathrooms] => 2
[NoOfDomesticRooms] => 0
[DomesticRoomsDescription] =>
[NoOfGarages] => 0
[GarageDescription] =>
[NoOfOutsideToilets] => 0
[Coverage] => 0
[Pool] => false
[PoolDescription] =>
[Flatlet] =>
[FlatletDescription] =>
[FlatletSize] =>
[EstablishedGarden] =>
[OutBuildingSize] =>
[NoOfCarports] => 0
[CarportsDescription] =>
[ParkingBayNumber] =>
[Parking] =>
[ParkingDescription] =>
[BusinessRights] =>
[HeightRestrictions] =>
[CommonFeatures] =>
[NumberOfShares] =>
[FacingOptions] =>
[KitchenOptions] =>
[FeatureOptions] =>
[SpecialFeatureOptions] =>
[WallOptions] =>
[WindowOptions] =>
[StyleOptions] =>
[TemperatureControlOptions] =>
[SecurityOptions] =>
[RoofOptions] =>
[RoomOptions] =>
[PoolOptions] =>
[BathroomOptions] =>
)
[AgentDetails] => Array
(
[InternetAgentName] => Ricky Duckworth
[InternetAgentPhoneNumber] => 0157931534
[InternetAgentEmailAddress] => ricky#propertylogic.net
[InternetAgentSMSNumber] => 0796057834
[ListingAgentCode] => CN21
[ListingAgencyCode] => CWP021
)
)
)
)
)
)
)
As you can see the array is structured fine. It's like SoapRequest has got to far into an array and stopped. I also get the notice
Notice: Array to string conversion in /var/www/vhosts/propertylogic.net/httpdocs/soap_feed/property24/add_property.php on line 178
Which is the SOAPCall line.
Thanks very much!
EDIT
[EDIT]Ok, basically the SOAP server requested that section to be raw xml, so I had to replace the Array with a String - sort of stupid way of doing things, but the error message now makes sense! (Can't answer my own question).
You'd better generate and use WSDL to create SOAP Client and define complex types there. This way every SOAP type will be converted to PHP types in a natural way (in your example it'll be an array of objects).
Or you can replace array with string as you did already, though it is a dirty magic :)