I am working on something in Wordpress and need to parse an array of objects and get some specific property information values.
I believe I am having issues be cause the property name has colons in it:
EX: id:DLM_Download_Version:private
The arrays name is $versions. This is the value of the array when i use print_r:
(
[0] => DLM_Download_Version Object
(
[id:DLM_Download_Version:private] => 208
[author:DLM_Download_Version:private] => 1
[download_id:DLM_Download_Version:private] => 196
[menu_order:DLM_Download_Version:private] => 0
[latest:DLM_Download_Version:private] =>
[date:DLM_Download_Version:private] => DateTime Object
(
[date] => 2022-03-22 12:48:00.000000
[timezone_type] => 3
[timezone] => UTC
)
[version:DLM_Download_Version:private] => 3
[download_count:DLM_Download_Version:private] => 0
[filesize:DLM_Download_Version:private] => 2966739
[md5:DLM_Download_Version:private] =>
[sha1:DLM_Download_Version:private] =>
[sha256:DLM_Download_Version:private] =>
[crc32b:DLM_Download_Version:private] =>
[mirrors:DLM_Download_Version:private] => Array
(
[0] => https://wordpress-360386-2306631.cloudwaysapps.com/wp-content/uploads/dlm_uploads/2022/03/STS-SENTIMENT-REPORT-3-21-22.pdf
)
[url:DLM_Download_Version:private] => https://wordpress-360386-2306631.cloudwaysapps.com/wp-content/uploads/dlm_uploads/2022/03/STS-SENTIMENT-REPORT-3-21-22.pdf
[filename:DLM_Download_Version:private] => STS-SENTIMENT-REPORT-3-21-22.pdf
[filetype:DLM_Download_Version:private] => pdf
)
[1] => DLM_Download_Version Object
(
[id:DLM_Download_Version:private] => 200
[author:DLM_Download_Version:private] => 1
[download_id:DLM_Download_Version:private] => 196
[menu_order:DLM_Download_Version:private] => 1
[latest:DLM_Download_Version:private] =>
[date:DLM_Download_Version:private] => DateTime Object
(
[date] => 2022-03-22 12:37:00.000000
[timezone_type] => 3
[timezone] => UTC
)
[version:DLM_Download_Version:private] => 2
[download_count:DLM_Download_Version:private] => 2
[filesize:DLM_Download_Version:private] => 3059630
[md5:DLM_Download_Version:private] =>
[sha1:DLM_Download_Version:private] =>
[sha256:DLM_Download_Version:private] =>
[crc32b:DLM_Download_Version:private] =>
[mirrors:DLM_Download_Version:private] => Array
(
[0] => https://wordpress-360386-2306631.cloudwaysapps.com/wp-content/uploads/dlm_uploads/2022/03/sts-weekly-sentiment-report-3-14-22.pdf
)
[url:DLM_Download_Version:private] => https://wordpress-360386-2306631.cloudwaysapps.com/wp-content/uploads/dlm_uploads/2022/03/sts-weekly-sentiment-report-3-14-22.pdf
[filename:DLM_Download_Version:private] => sts-weekly-sentiment-report-3-14-22.pdf
[filetype:DLM_Download_Version:private] => pdf
)
[2] => DLM_Download_Version Object
(
[id:DLM_Download_Version:private] => 197
[author:DLM_Download_Version:private] => 1
[download_id:DLM_Download_Version:private] => 196
[menu_order:DLM_Download_Version:private] => 2
[latest:DLM_Download_Version:private] =>
[date:DLM_Download_Version:private] => DateTime Object
(
[date] => 2022-03-22 12:35:00.000000
[timezone_type] => 3
[timezone] => UTC
)
[version:DLM_Download_Version:private] => 1
[download_count:DLM_Download_Version:private] => 0
[filesize:DLM_Download_Version:private] => 2648776
[md5:DLM_Download_Version:private] =>
[sha1:DLM_Download_Version:private] =>
[sha256:DLM_Download_Version:private] =>
[crc32b:DLM_Download_Version:private] =>
[mirrors:DLM_Download_Version:private] => Array
(
[0] => https://wordpress-360386-2306631.cloudwaysapps.com/wp-content/uploads/dlm_uploads/2022/03/STS-WEEKLY-SENTIMENT-REPORT-3-8-22.pdf
)
[url:DLM_Download_Version:private] => https://wordpress-360386-2306631.cloudwaysapps.com/wp-content/uploads/dlm_uploads/2022/03/STS-WEEKLY-SENTIMENT-REPORT-3-8-22.pdf
[filename:DLM_Download_Version:private] => STS-WEEKLY-SENTIMENT-REPORT-3-8-22.pdf
[filetype:DLM_Download_Version:private] => pdf
)
)
How can I get just the values of id:DLM_Download_Version:private?
I have tried a foreach loop:
foreach ($versions as $version){
echo $version->{'id:DLM_Download_Version:private'}
}
which just outputs nothing.
Related
I'am tryng to get the value that an adress sent me on my adress, I have already setted up the webhook, but i can't understand a thing...
I have this array->
Array
(
[network] => tBTC
[event_type] => address-transactions
[addresses] => Array
(
[2MyXzRYSzrExLitY6FumGC3QgzCeqVoeQC1] => -49320
)
[data] => Array
(
[raw] =>
[hash] =>
[first_seen_at] => 2017-10-13T17:19:35+0000
[last_seen_at] => 2017-10-13T17:19:35+0000
[block_height] => 1210150
[block_time] => 2017-10-13T17:20:18+0000
[block_hash] =>
[confirmations] => 2
[is_coinbase] =>
[estimated_value] => 30000
[total_input_value] => 49320
[total_output_value] => 45510
[total_fee] => 3810
[estimated_change] => 15510
[estimated_change_address] => 2N7iSxafSoio4RE8wrd6outJNmbMkyP9QuL
[high_priority] =>
[enough_fee] =>
[contains_dust] =>
[inputs] => Array
(
[0] => Array
(
[index] => 0
[output_hash] =>
[output_index] => 0
[output_confirmed] => 1
[value] => 49320
[sequence] => 4294967295
[address] => 2MyXzRYSzrExLitY6FumGC3QgzCeqVoeQC1
[type] => scripthash
[multisig] =>
[multisig_addresses] =>
[script_signature] =>
)
)
[outputs] => Array
(
[0] => Array
(
[index] => 0
[value] => 30000
[address] => 2NBkQ8aTq8yeXdMWtxXNuxNgEHYnrzvcpV2
[type] => scripthash
[multisig] =>
[multisig_addresses] =>
[script] => OP_HASH160 OP_EQUAL
[script_hex] =>
[spent_hash] =>
[spent_index] => 0
)
[1] => Array
(
[index] => 1
[value] => 15510
[address] => 2N7iSxafSoio4RE8wrd6outJNmbMkyP9QuL
[type] => scripthash
[multisig] =>
[multisig_addresses] =>
[script] => OP_HASH160 OP_EQUAL
[script_hex] =>
[spent_hash] =>
[spent_index] => 0
)
)
[opt_in_rbf] =>
[unconfirmed_inputs] =>
[lock_time_timestamp] =>
[lock_time_block_height] =>
[size] => 367
)
[retry_count] => 0
And I'am tryng to get ONLY THE VALUE OF BTC (SATOSHI) THAT COME ON MY ADRESS, SO WITH THE SUBSTRACTION OF THE FEES, i thought that for get this values I had to get the
$Data=BlocktrailSDK::getWebhookPayload();
$Data['data']['estimated_value'];
Is this correct way to get at the 1000000% THE VALUE OF BTC (SATOSHI) THAT COME ON MY ADRESS, SO WITH THE SUBSTRACTION OF THE FEES, if is not what is the correct way??Anyway thanks for ready, hope that you all had a good day, and thanks for your time :)
P.S Note that on this transaction i sent 30000 satoshi+fees!
I have a simple code and when I print_r it, this one is the output:
Array
(
[0] => App\Entities\EibPerson Object
(
[personId:App\Entities\EibPerson:private] => 10025
[createdBy:App\Entities\EibPerson:private] => 1
[createdOn:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 2016-12-06 08:33:59.000000
[timezone_type] => 1
[timezone] => +03:00
)
[modifiedBy:App\Entities\EibPerson:private] => 1
[modifiedOn:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 2016-12-06 08:33:59.000000
[timezone_type] => 1
[timezone] => +03:00
)
[recordVersion:App\Entities\EibPerson:private] => 1
[activeFlag:App\Entities\EibPerson:private] => 1
[firstName:App\Entities\EibPerson:private] => test person name
[middleName:App\Entities\EibPerson:private] => test middle
[lastName:App\Entities\EibPerson:private] => test last name
[displayName:App\Entities\EibPerson:private] => sorxrob
[dateOfBirth:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 1992-10-01 03:00:00.000000
[timezone_type] => 1
[timezone] => +03:00
)
[landlineNumber:App\Entities\EibPerson:private] => 2312321313131
[mobileNumber:App\Entities\EibPerson:private] => 876543454
[emailAddress:App\Entities\EibPerson:private] => sorianorobertc#gmail.com
[heightInches:App\Entities\EibPerson:private] => 6
[inseamLengthInches:App\Entities\EibPerson:private] => 6
[weightInKgs:App\Entities\EibPerson:private] => 80.00
[profilePictureUrl:App\Entities\EibPerson:private] =>
[sourceDesc:App\Entities\EibPerson:private] => testsourceDesc
[remarks:App\Entities\EibPerson:private] => test remarks test
[memberId:App\Entities\EibPerson:private] =>
[externalReferenceId:App\Entities\EibPerson:private] =>
[genderEnumRid:App\Entities\EibPerson:private] =>
[address:App\Entities\EibPerson:private] =>
[tshirtSizeEnumRid:App\Entities\EibPerson:private] =>
[bloodGroupEnumRid:App\Entities\EibPerson:private] =>
[managingBranch:App\Entities\EibPerson:private] =>
[foodPreferenceEnumRid:App\Entities\EibPerson:private] =>
[sourceEnumRid:App\Entities\EibPerson:private] =>
[sourceDetailRid:App\Entities\EibPerson:private] =>
[externalSourceSysEnumRid:App\Entities\EibPerson:private] =>
)
[1] => App\Entities\EibPerson Object
(
[personId:App\Entities\EibPerson:private] => 10026
[createdBy:App\Entities\EibPerson:private] => 1
[createdOn:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 2016-12-06 08:36:03.000000
[timezone_type] => 1
[timezone] => +03:00
)
[modifiedBy:App\Entities\EibPerson:private] => 1
[modifiedOn:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 2016-12-06 08:36:03.000000
[timezone_type] => 1
[timezone] => +03:00
)
[recordVersion:App\Entities\EibPerson:private] => 1
[activeFlag:App\Entities\EibPerson:private] => 1
[firstName:App\Entities\EibPerson:private] => test person name
[middleName:App\Entities\EibPerson:private] => test middle
[lastName:App\Entities\EibPerson:private] => test last name
[displayName:App\Entities\EibPerson:private] => sorxrob
[dateOfBirth:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 1992-10-01 03:00:00.000000
[timezone_type] => 1
[timezone] => +03:00
)
[landlineNumber:App\Entities\EibPerson:private] => 2312321313131
[mobileNumber:App\Entities\EibPerson:private] => 876543454
[emailAddress:App\Entities\EibPerson:private] => sorianorobertc#gmail.com
[heightInches:App\Entities\EibPerson:private] => 6
[inseamLengthInches:App\Entities\EibPerson:private] => 6
[weightInKgs:App\Entities\EibPerson:private] => 80.00
[profilePictureUrl:App\Entities\EibPerson:private] =>
[sourceDesc:App\Entities\EibPerson:private] => testsourceDesc
[remarks:App\Entities\EibPerson:private] => test remarks test
[memberId:App\Entities\EibPerson:private] =>
[externalReferenceId:App\Entities\EibPerson:private] =>
[genderEnumRid:App\Entities\EibPerson:private] =>
[address:App\Entities\EibPerson:private] =>
[tshirtSizeEnumRid:App\Entities\EibPerson:private] =>
[bloodGroupEnumRid:App\Entities\EibPerson:private] =>
[managingBranch:App\Entities\EibPerson:private] =>
[foodPreferenceEnumRid:App\Entities\EibPerson:private] =>
[sourceEnumRid:App\Entities\EibPerson:private] =>
[sourceDetailRid:App\Entities\EibPerson:private] =>
[externalSourceSysEnumRid:App\Entities\EibPerson:private] =>
)
[2] => App\Entities\EibPerson Object
(
[personId:App\Entities\EibPerson:private] => 10027
[createdBy:App\Entities\EibPerson:private] => 1
[createdOn:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 2016-12-06 08:37:25.000000
[timezone_type] => 1
[timezone] => +03:00
)
[modifiedBy:App\Entities\EibPerson:private] => 1
[modifiedOn:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 2016-12-06 08:37:25.000000
[timezone_type] => 1
[timezone] => +03:00
)
[recordVersion:App\Entities\EibPerson:private] => 1
[activeFlag:App\Entities\EibPerson:private] => 1
[firstName:App\Entities\EibPerson:private] => test person name
[middleName:App\Entities\EibPerson:private] => test middle
[lastName:App\Entities\EibPerson:private] => test last name
[displayName:App\Entities\EibPerson:private] => sorxrob
[dateOfBirth:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 1992-10-01 03:00:00.000000
[timezone_type] => 1
[timezone] => +03:00
)
[landlineNumber:App\Entities\EibPerson:private] => 2312321313131
[mobileNumber:App\Entities\EibPerson:private] => 876543454
[emailAddress:App\Entities\EibPerson:private] => sorianorobertc#gmail.com
[heightInches:App\Entities\EibPerson:private] => 6
[inseamLengthInches:App\Entities\EibPerson:private] => 6
[weightInKgs:App\Entities\EibPerson:private] => 80.00
[profilePictureUrl:App\Entities\EibPerson:private] =>
[sourceDesc:App\Entities\EibPerson:private] => testsourceDesc
[remarks:App\Entities\EibPerson:private] => test remarks test
[memberId:App\Entities\EibPerson:private] =>
[externalReferenceId:App\Entities\EibPerson:private] =>
[genderEnumRid:App\Entities\EibPerson:private] =>
[address:App\Entities\EibPerson:private] =>
[tshirtSizeEnumRid:App\Entities\EibPerson:private] =>
[bloodGroupEnumRid:App\Entities\EibPerson:private] =>
[managingBranch:App\Entities\EibPerson:private] =>
[foodPreferenceEnumRid:App\Entities\EibPerson:private] =>
[sourceEnumRid:App\Entities\EibPerson:private] =>
[sourceDetailRid:App\Entities\EibPerson:private] =>
[externalSourceSysEnumRid:App\Entities\EibPerson:private] =>
)
)
My code:
$person = $this->em->getRepository('App\Entities\EibPerson')->findAll();
print_r($person);
What I actually want is to only get this:
How can I possibly do that? Because I want to json_encode the array but im getting an empty json..
Debug with max depth
You could use maxDepth variable of Doctrine Dump.
You can use \Doctrine\Common\Util\Debug::dump($variable, $depth); it displays doctrine output without the proxy information.
More readable output
If you are using symfony 2.6 or more, I strongly advice you to use dump() instead of var_dump() or print_r().
Dump shows a well formated and colored output, and you can expand/hide rows.
Finally... to json
To export object(s) to json, I advice you to use serializer and normalizer services, you can find here in the documentation
Cleeng_Entity_Collection Object
(
[entityType:protected] => Cleeng_Entity_SubscriptionOffer
[items:protected] => Array
(
[0] => Cleeng_Entity_SubscriptionOffer Object
(
[id:protected] => S955494970_US
[publisherEmail:protected] => vidya+mtc#ooyala.com
[url:protected] =>
[title:protected] => Annual subscription
[description:protected] =>
[period:protected] => year
[price:protected] => 49.99
[applicableTaxRate:protected] => 0
[currency:protected] => USD
[accessToTags:protected] => Array
(
[0] => d962607d3d4c4e3c98a343c7bcb64027
)
[active:protected] => 1
[createdAt:protected] => 1473681112
[updatedAt:protected] => 1473858745
[geoRestrictionEnabled:protected] =>
[geoRestrictionType:protected] =>
[geoRestrictionCountries:protected] => Array
(
)
[pending:protected] =>
[country] => US
[socialCommissionRate] => 0
[averageRating] => 4
[contentType] =>
[freePeriods] => 0
[freeDays] => 0
[expiresAt] =>
)
)
[totalItemCount:protected] => 5
[pending:protected] =>
)
All you need to do is just convert the Collection to a Regular Array and then json_encode() the Result like so:
<?php
$entityCollection = "???"; // THIS IS THE DATA FROM Cleeng_Entity_Collection Object
$entityArray = $entityCollection->toArray();
$entityJSON = json_encode($entityArray);
I query db and I have an array. How can I access stdClass object ? And I want also serializedName property like in java serializedName. So, The fields which query from db must be assign with my custom object class fields.How can I use this?
Array
(
[0] => stdClass Object
(
[receipt_id] => 1
[defect] => asd
[tec_report] => sad
[doc_number] => asd
[warrant] => 12
[warrant_start] => 2016-01-05
[warrant_end] => 2016-01-29
[repair_time] => 3
[receipt_date] => 2016-01-05
[delivery_date] =>
[service_type_id] => 0
[service_price] => 0
[part_price] => 0
[pay_type] =>
[labour] => 0
[summary] => 0
[technician_id] =>
[customer_id] => 0
[device_id] => 0
[seri_number] =>
)
[1] => stdClass Object
(
[receipt_id] => 2
[defect] => asdsad
[tec_report] => asds
[doc_number] =>
[warrant] =>
[warrant_start] =>
[warrant_end] =>
[repair_time] =>
[receipt_date] => 2016-01-05
[delivery_date] =>
[service_type_id] => 1
[service_price] => 12
[part_price] => 12
[pay_type] =>
[labour] => 12
[summary] => 12
[technician_id] =>
[customer_id] => 21
[device_id] => 12
[seri_number] =>
)
)
try this for one by one
echo $array[0]->receipt_id;
try this :
foreach($yourArray as $val){
echo $val->receipt_id;
echo "<br/>".$val->defect;
}
PHP - Access MSSQL datetime column from the returned array
Array
(
[0] => Array
(
[CallId] => 45
[CallLoginId] => 1
[CustomerId] => 140
[CallOptionId] => 2
[CallTypeId] => 2
[CallStatusId] => 1
[CallDateTime] => DateTime Object
(
[date] => 2012-06-28 00:00:00
[timezone_type] => 3
[timezone] => Asia/Kolkata
)
[ContactNo] => 45151551115
[ContactPerson] => Contact Person name
[ProductId] => 1
[ProdCompanyId] => 1
[ProdCategoryId] => 1
[ModelNo] => 451212151
[ProdUnderId] => 1
[Problem] => Simple Problem Details
[Remarks] => Remarks
[Accessories] => Accessories
[CallCaseId] =>
[CallCaseDate] =>
[ServiceCharge] => 0
[CourierName] =>
[DocketNo] =>
[CompanyId] => 126
[ASPId] => 130
[InsBy] => 134
[InsDate] => DateTime Object
(
[date] => 2012-06-23 17:04:51
[timezone_type] => 3
[timezone] => Asia/Kolkata
)
[UpdBy] => 11
[UpdDate] => DateTime Object
(
[date] => 2012-06-28 18:29:23
[timezone_type] => 3
[timezone] => Asia/Kolkata
)
[FName] => Kumar
[MName] => a
[LName] => Customer
[ProductName] => LenovoDesktop420
[CallOption] => InHouse
[CallType] => H.W.Installation
[ProdCompany] => Lenovo
[ProdCategory] => Desktop
[ProdUnder] => AMC
[CallStatus] => Open
[EntityId] => 134
[InsertBy] => Bhavin Rana
)
)
how can access date time value form this returned array ?
thanks in advance.
You have an outer array with numerically indexed one element [0], which is an associative array. CallDateTime as a key of that array is a DateTime object.
$array[0]['CallDateTime']->format('Y-m-d H:i:s') // 2012-06-28 00:00:00
$array[0]['CallDateTime']->getTimezone()->getName() // Asia/Kolkata
// Same with InsDate and UpdDate
$array[0]['InsDate']->format('Y-m-d H:i:s') // 2012-06-23 17:04:51
$array[0]['InsDate']->getTimezone()->getName() // Asia/Kolkata