How to remove current part from php file in php? - php

I have project for upload files on server, but I want to save them in php file ...
thats okay.. But when I want to delete them from the array with str_replace() It`s not happen...
from this array:
$files = array(
'2920525' => array(
'name' => 'Penguins',
'size' => '759.6 KB',
'unzip2920525' => NULL,
'pass2920525' => NULL,
'share2920525' => NULL,
'path' => 'uploads/anton_markov/99865723_Penguins.jpg',
),
'2683777' => array(
'name' => 'Lighthouse',
'size' => '548.1 KB',
'unzip2683777' => NULL,
'pass2683777' => NULL,
'share2683777' => NULL,
'path' => 'uploads/anton_markov/68670654_Lighthouse.jpg',
),
'6456807' => array(
'name' => 'Lighthouse - Копие - Копие',
'size' => '548.1 KB',
'unzip6456807' => NULL,
'pass6456807' => NULL,
'share6456807' => NULL,
'path' => 'uploads/anton_markov/94653321_Lighthouse---opie---opie.jpg',
),
'2363848' => array(
'name' => 'Koala',
'size' => '762.5 KB',
'unzip2363848' => NULL,
'pass2363848' => NULL,
'share2363848' => NULL,
'path' => 'uploads/anton_markov/15704345_Koala.jpg',
),
'6172497' => array(
'name' => 'Lighthouse',
'size' => '548.1 KB',
'unzip6172497' => NULL,
'pass6172497' => NULL,
'share6172497' => NULL,
'path' => 'uploads/anton_markov/53317261_Lighthouse.jpg',
),
);
I want to remove:
'6456807' => array(
'name' => 'Lighthouse - Копие - Копие',
'size' => '548.1 KB',
'unzip6456807' => NULL,
'pass6456807' => NULL,
'share6456807' => NULL,
'path' => 'uploads/anton_markov/94653321_Lighthouse---opie---opie.jpg',
),
I try with str_replace(),preg_replace() But nothing happen. I dont know why. When I remove the value from the array I want to save it. Please help me.

Just use unset.
unset($files['6456807']);

Related

Laravel - Validate at least one field from an array

I have this data:
[2022-12-07 11:56:19] local.INFO: array (
'name' => NULL,
'import_period' => NULL,
'google_ads_account' => NULL,
'period' => NULL,
'period_date_from' => NULL,
'period_date_to' => NULL,
'id_campaigns' =>
array (
0 =>
array (
'id_campaign' => NULL,
),
),
'id_adgroups' =>
array (
0 =>
array (
'id_adgroup' => NULL,
),
),
'campaign_name_contains' => NULL,
'adgroup_name_contains' => NULL,
'click' => 'less_than',
'click_value' => NULL,
'click_from' => NULL,
'click_to' => NULL,
'impressions' => 'less_than',
'impressions_value' => NULL,
'impressions_from' => NULL,
'impressions_to' => NULL,
'cost' => 'less_than',
'cost_value' => NULL,
'cost_from' => NULL,
'cost_to' => NULL,
'conversions' => 'less_than',
'conversions_value' => NULL,
'conversions_from' => NULL,
'conversions_to' => NULL,
'mapping_list' =>
array (
0 =>
array (
'value' => 'conversions',
'text' => NULL,
),
1 =>
array (
'value' => 'roas',
'text' => NULL,
),
2 =>
array (
'value' => 'all_conversions',
'text' => NULL,
),
3 =>
array (
'value' => 'all_conversions_from_interactions_rate',
'text' => NULL,
),
4 =>
array (
'value' => 'ctr',
'text' => NULL,
),
5 =>
array (
'value' => 'average_cpc',
'text' => NULL,
),
6 =>
array (
'value' => 'clicks',
'text' => NULL,
),
7 =>
array (
'value' => 'impressions',
'text' => NULL,
),
8 =>
array (
'value' => 'cost',
'text' => NULL,
),
9 =>
array (
'value' => 'conversions_value',
'text' => NULL,
),
10 =>
array (
'value' => 'conversions_from_interactions_rate',
'text' => NULL,
),
11 =>
array (
'value' => 'cost_per_conversion',
'text' => NULL,
),
12 =>
array (
'value' => 'search_click_share',
'text' => NULL,
),
13 =>
array (
'value' => 'search_impression_share',
'text' => NULL,
),
14 =>
array (
'value' => 'value_per_all_conversions',
'text' => NULL,
),
15 =>
array (
'value' => 'value_per_conversion',
'text' => NULL,
),
),
)
I am validating this data like this:
$validator = Validator::make($request->all(), [
'name' => 'required',
'import_period' => 'required',
'google_ads_account' => 'required',
'period' => 'required',
'period_date_from' => 'required_if:period,custom',
'period_date_to' => 'required_if:period,custom',
'id_campaigns.*.id_campaign'=> 'required',
'id_adgroups.*.id_adgroup' => 'required',
'campaign_name_contains' => 'required',
'adgroup_name_contains' => 'required',
'mapping_list.*.text' => 'required|min:1',
'click' => 'required',
'click_value' => 'required_if:click,greater_than,less_than',
'click_from' => 'required_if:click,between',
'click_to' => 'required_if:click,between',
'cost' => 'required',
'cost_value' => 'required_if:cost,greater_than,less_than',
'cost_from' => 'required_if:cost,between',
'cost_to' => 'required_if:cost,between',
'impressions' => 'required',
'impressions_value' => 'required_if:impressions,greater_than,less_than',
'impressions_from' => 'required_if:impressions,between',
'impressions_to' => 'required_if:impressions,between',
'conversions' => 'required',
'conversions_value' => 'required_if:conversions,greater_than,less_than',
'conversions_from' => 'required_if:conversions,between',
'conversions_to' => 'required_if:conversions,between',
]);
Here on this line 'mapping_list.*.text' => 'required|min:1' I am trying to validate this mapping_list array.
I want at least one field should be filled up but I have to fill up every element of this array.
Can you tell me is there anyting I am doing wrong?
If you want to validate that at least one field is filled, you must specify which field you want to validate. For example (in your code):
'mapping_list.*.text' => 'required|min:1',
you can change
'mapping_list.[0].text' => 'required|min:1',
or
'mapping_list.[1].text' => 'required|min:1',
That should be all you need to do. Hopefully that helps!

Freeswitch - Parse Call Detail Record information

I have Freeswitch server sending CDR information (A leg only) in JSON to PHP script and I need to parse extension and phone number in every scenario possible:
Incoming call from PSTN to: user, group, callcenter app (answered, un-answered)
Outgoing call to PSTN from user (answered, un-answered)
Each scenario have to use different variable in the JSON - depends if was bridged or not, if it's incoming (destination_number), if it's outgoing (caller_id_number), etc.
I was using bridge_uuid to detect if the call was bridged, but still got calls where bridge_uuid is missing and last_app is bridge (with status ORIGINATOR_CANCEL).
I put together 7 scenarios, but still there are calls, where phone number appear in extension for some reason and vice-versa.
Is there any simple way to get this information from CDR?
SCENARIO 1:
outbound
bridge_uuid = exists
extension = callflow.0.caller_profile.caller_id_number
number = callflow.0.caller_profile.destination_number
SCENARIO 2:
outbound
bridge_uuid = not exists
extension = callflow.0.caller_profile.destination_number
number = callflow.0.caller_profile.caller_id_number
SCENARIO 3:
outbound
bridge_uuid = not exists
last_app = bridge
extension = callflow.0.caller_profile.caller_id_number
number = callflow.0.caller_profile.destination_number
SCENARIO 4:
inbound
bridge_uuid = exists
cc_agent_bridged = exists
extension = callflow.0.caller_profile.originatee.originatee_caller_profiles.0.destination_number
number = callflow.0.caller_profile.caller_id_number
SCENARIO 5:
inbound
bridge_uuid = exists
cc_agent_bridged = not exists
extension = callflow.0.caller_profile.caller_id_number
number = callflow.0.caller_profile.destination_number
SCENARIO 6:
inbound
bridge_uuid = not exists
extension = NULL
number = callflow.0.caller_profile.caller_id_number
SCENARIO 7:
inbound
bridge_uuid = exists
cc_agent_bridged = not exists
extension = ???
number = ???
JSON CDR
'core-uuid' => 'bf6eef3c-16b7-4f61-8cc2-1cd73460268e',
'switchname' => 'freeswitch',
'channel_data' =>
array (
'state' => 'CS_REPORTING',
'direction' => 'outbound',
'state_number' => '11',
'flags' => '0=1;2=1;22=1;40=1;42=1;45=1;116=1;117=1',
'caps' => '1=1;2=1;3=1;4=1;5=1;6=1;8=1;9=1;10=1',
),
'callStats' =>
array (
),
'variables' =>
array (
'direction' => 'outbound',
'is_outbound' => 'true',
'uuid' => 'c9aa9f5f-7afd-46af-8cca-2af25b758aec',
'call_uuid' => 'c9aa9f5f-7afd-46af-8cca-2af25b758aec',
'session_id' => '4755',
'sip_profile_name' => 'homeoffice',
'video_media_flow' => 'disabled',
'text_media_flow' => 'disabled',
'channel_name' => 'sofia/homeoffice/4012%40XXX.XXX.XXX.XXX%3A56955',
'sip_destination_url' => 'sip%3A4012%40XXX.XXX.XXX.XXX%3A56955%3Btransport%3DUDP%3Brinstance%3D845ce1bf3f9efbf1%3Bfs_nat%3Dyes%3Bfs_path%3Dsip%3A4012%40XXX.XXX.XXX.XXX%3A56955%3Btransport%3DUDP%3Brinstance%3D845ce1bf3f9efbf1',
'origination_caller_id_name' => 'Name%20Surname',
'origination_caller_id_number' => '1829XXXXXXX',
'EXT_ID' => '163748',
'USER_ID' => '793',
'ID_TYPE' => 'application',
'callgroup' => 'local',
'dialed_user' => '4012',
'dialed_domain' => 'pbx.domain.com',
'sip_invite_domain' => 'pbx.domain.com',
'presence_id' => '4012%40pbx.domain.com',
'originate_early_media' => 'true',
'rtp_use_codec_string' => 'OPUS,G729,PCMU,PCMA,GSM',
'local_media_ip' => 'XXX.XXX.XXX.XXX',
'local_media_port' => '17432',
'advertised_media_ip' => 'XXX.XXX.XXX.XXX',
'audio_media_flow' => 'sendrecv',
'rtp_local_sdp_str' => 'v%3D0%0D%0Ao%3DFreeSWITCH%201646156158%201646156159%20IN%20IP4%20XXX.XXX.XXX.XXX%0D%0As%3DFreeSWITCH%0D%0Ac%3DIN%20IP4%20XXX.XXX.XXX.XXX%0D%0At%3D0%200%0D%0Am%3Daudio%2017432%20RTP/AVP%20102%2018%200%208%203%20103%20101%0D%0Aa%3Drtpmap%3A102%20opus/48000/2%0D%0Aa%3Dfmtp%3A102%20useinbandf
ec%3D1%3B%20maxaveragebitrate%3D30000%3B%20maxplaybackrate%3D48000%3B%20ptime%3D20%3B%20minptime%3D10%3B%20maxptime%3D40%0D%0Aa%3Drtpmap%3A18%20G729/8000%0D%0Aa%3Dfmtp%3A18%20annexb%3Dno%0D%0Aa%3Drtpmap%3A0%20PCMU/8000%0D%0Aa%3Drtpmap%3A8%20PCMA/8000%0D%0Aa%3Drtpmap%3A3%20GSM/8000%0D%0Aa%3Drtpmap%3A103%20telephone-e
vent/48000%0D%0Aa%3Dfmtp%3A103%200-15%0D%0Aa%3Drtpmap%3A101%20telephone-event/8000%0D%0Aa%3Dfmtp%3A101%200-15%0D%0Aa%3Dptime%3A20%0D%0Aa%3Dsendrecv%0D%0A',
'sip_outgoing_contact_uri' => '%3Csip%3Amod_sofia%40XXX.XXX.XXX.XXX%3A5090%3E',
'sip_req_uri' => '4012%40XXX.XXX.XXX.XXX%3A56955%3Btransport%3DUDP%3Brinstance%3D845ce1bf3f9efbf1',
'sip_nat_detected' => 'true',
'sofia_profile_name' => 'office',
'recovery_profile_name' => 'office',
'sofia_profile_url' => 'sip%3Amod_sofia%40XXX.XXX.XXX.XXX%3A5090',
'sip_local_network_addr' => 'XXX.XXX.XXX.XXX',
'sip_reply_host' => 'XXX.XXX.XXX.XXX',
'sip_reply_port' => '56955',
'sip_network_ip' => 'XXX.XXX.XXX.XXX',
'sip_network_port' => '56955',
'sip_user_agent' => 'Z%205.5.9%20v2.10.17.3',
'sip_allow' => 'INVITE,%20ACK,%20CANCEL,%20BYE,%20NOTIFY,%20REFER,%20MESSAGE,%20OPTIONS,%20INFO,%20SUBSCRIBE',
'sip_recover_contact' => '%3Csip%3A4012%40XXX.XXX.XXX.XXX%3A56955%3Btransport%3DUDP%3E',
'sip_full_via' => 'SIP/2.0/UDP%20XXX.XXX.XXX.XXX%3A5090%3Brport%3D5090%3Bbranch%3Dz9hG4bKS6tvm613tKgpg',
'sip_recover_via' => 'SIP/2.0/UDP%20XXX.XXX.XXX.XXX%3A5090%3Brport%3D5090%3Bbranch%3Dz9hG4bKS6tvm613tKgpg',
'sip_from_display' => 'Name%20Surname',
'sip_full_from' => '%22Name%20Surname%22%20%3Csip%3A1829XXXXXXX%40pbx.domain.com%3E%3Btag%3DDc8U2HQFrDQ4D',
'sip_full_to' => '%3Csip%3A4012%40XXX.XXX.XXX.XXX%3A56955%3Btransport%3DUDP%3Brinstance%3D845ce1bf3f9efbf1%3E%3Btag%3De4ab0722',
'sip_from_user' => '1829XXXXXXX',
'sip_from_uri' => '1829XXXXXXX%40pbx.domain.com',
'sip_from_host' => 'pbx.domain.com',
'sip_to_params' => 'transport%3DUDP%3Brinstance%3D845ce1bf3f9efbf1',
'sip_to_user' => '4012',
'sip_to_port' => '56955',
'sip_to_uri' => '4012%40XXX.XXX.XXX.XXX%3A56955',
'sip_to_host' => 'XXX.XXX.XXX.XXX',
'sip_contact_params' => 'transport%3DUDP',
'sip_contact_user' => '4012',
'sip_contact_port' => '56955',
'sip_contact_uri' => '4012%40XXX.XXX.XXX.XXX%3A56955',
'sip_contact_host' => 'XXX.XXX.XXX.XXX',
'sip_to_tag' => 'e4ab0722',
'sip_from_tag' => 'Dc8U2HQFrDQ4D',
'sip_cseq' => '48533003',
'sip_call_id' => '7ba03d12-1451-123b-ff84-ac1f6b94e36c',
'hangup_cause' => 'NO_ANSWER',
'hangup_cause_q850' => '19',
'digits_dialed' => 'none',
'start_stamp' => '2022-03-01%2018%3A26%3A30',
'profile_start_stamp' => '2022-03-01%2018%3A26%3A30',
'progress_stamp' => '2022-03-01%2018%3A26%3A30',
'end_stamp' => '2022-03-01%2018%3A27%3A30',
'start_epoch' => '1646173590',
'start_uepoch' => '1646173590060292',
'profile_start_epoch' => '1646173590',
'profile_start_uepoch' => '1646173590060292',
'answer_epoch' => '0',
'answer_uepoch' => '0',
'bridge_epoch' => '0',
'bridge_uepoch' => '0',
'last_hold_epoch' => '0',
'last_hold_uepoch' => '0',
'hold_accum_seconds' => '0',
'hold_accum_usec' => '0',
'hold_accum_ms' => '0',
'resurrect_epoch' => '0',
'resurrect_uepoch' => '0',
'progress_epoch' => '1646173590',
'progress_uepoch' => '1646173590620111',
'progress_media_epoch' => '0',
'progress_media_uepoch' => '0',
'end_epoch' => '1646173650',
'end_uepoch' => '1646173650000174',
'caller_id' => '%22Name%20Surname%22%20%3C1829XXXXXXX%3E',
'duration' => '60',
'billsec' => '0',
'progresssec' => '0',
'answersec' => '0',
'waitsec' => '0',
'progress_mediasec' => '0',
'flow_billsec' => '0',
'mduration' => '59940',
'billmsec' => '0',
'progressmsec' => '560',
'answermsec' => '0',
'waitmsec' => '0',
'progress_mediamsec' => '0',
'flow_billmsec' => '0',
'uduration' => '59939882',
'billusec' => '0',
'progressusec' => '559819',
'answerusec' => '0',
'waitusec' => '0',
'progress_mediausec' => '0',
'flow_billusec' => '0',
'sip_hangup_disposition' => 'send_cancel',
'sip_invite_failure_status' => '487',
'sip_invite_failure_phrase' => 'CANCEL',
),
'callflow' =>
array (
0 =>
array (
'profile_index' => '1',
'caller_profile' =>
array (
'username' => '',
'dialplan' => '',
'caller_id_name' => 'Name Surname',
'ani' => '1829XXXXXXX',
'aniii' => '',
'caller_id_number' => '1829XXXXXXX',
'network_addr' => 'XXX.XXX.XXX.XXX',
'rdnis' => '',
'destination_number' => '4012',
'uuid' => 'c9aa9f5f-7afd-46af-8cca-2af25b758aec',
'source' => 'src/switch_ivr_originate.c',
'context' => 'default',
'chan_name' => 'sofia/office/4012#XXX.XXX.XXX.XXX:56955',
),
'times' =>
array (
'created_time' => '1646173590060292',
'profile_created_time' => '1646173590060292',
'progress_time' => '1646173590620111',
'progress_media_time' => '0',
'answered_time' => '0',
'bridged_time' => '0',
'last_hold_time' => '0',
'hold_accum_time' => '0',
'hangup_time' => '1646173650000174',
'resurrect_time' => '0',
'transfer_time' => '0',
),
),
),
)
PHP SCRIPT
$data = json_decode($data_above, true);
$bridged = isset($data['variables']['bridge_uuid']);
$callcenter = isset($data['variables']['cc_agent_bridged']);
$direction = $data['variables']['direction'];
$extension = $data['callflow'][0]['caller_profile'];
$extension = match($direction)
{
'inbound'=>match($bridged)
{
true => match($callcenter)
{
true => $extension['originatee']['originatee_caller_profiles'][0]['destination_number'],
false => 'caller_id_number'
},
false => ''
},
'outbound'=>match($bridged)
{
true => 'caller_id_number',
false => $data['variables']['last_app'] == 'bridge' ? 'caller_id_number' : 'destination_number'
}
};

Get specific data from the array

Since I'm really unexperienced with PHP, I'm having trouble retrieving specific data from the following array that I receive via API:
I need the values of
'id'
'amount'
'statsTags'
Unfortunatly the following code retrieves an undefined index error:
echo $commissions['TPerformant\API\Model\Commission::__set_state']['id'];
This is the content of the var_dump
var_dump($commissions):
array (
0 =>
TPerformant\API\Model\Commission::__set_state(array(
'id' => 457171,
'userId' => 8917,
'actionid' => 456657,
'actiontype' => 'sale',
'amount' => '0.31',
'status' => 'pending',
'affrequestId' => NULL,
'description' => 'cosmetics|Mascara Extra Super Lash Curved Brush 8 mlx1 (7% from 6.66), cosmetics|Sampon uscat Blush Dry 50 mlx1 (7% from 8.33), cosmetics|Crema de maini si corp cu Lavandax1 (7% from 4.99)',
'createdAt' => '2016-12-24T16:48:07Z',
'updatedAt' => '2016-12-24T16:48:07Z',
'reason' => NULL,
'statsTags' => ',undefinedDesktopnulla60949bd-0b06-4fd6-a324-0d65351c10e9,',
'history' => NULL,
'currency' => 'EUR',
'workingCurrencyCode' => 'RON',
'programId' => 882,
'amountInWorkingCurrency' => '1.4',
'program' =>
TPerformant\API\Model\AffiliateProgram::__set_state(array(
'affrequest' => NULL,
'id' => NULL,
'slug' => 'elefant-ro',
'name' => 'elefant.ro ',
'mainUrl' => NULL,
'baseUrl' => NULL,
'description' => NULL,
'activatedAt' => NULL,
'userId' => NULL,
'uniqueCode' => NULL,
'status' => NULL,
'cookieLife' => NULL,
'tos' => NULL,
'productFeedsCount' => NULL,
'productsCount' => NULL,
'bannersCount' => NULL,
'approvalTime' => NULL,
'currency' => NULL,
'enableLeads' => NULL,
'enableSales' => NULL,
'defaultLeadCommissionRate' => NULL,
'defaultLeadCommissionType' => NULL,
'defaultSaleCommissionRate' => NULL,
'defaultSaleCommissionType' => NULL,
'approvedCommissionCountRate' => NULL,
'approvedCommissionAmountRate' => NULL,
'paymentType' => 'postpaid',
'balanceIndicator' => NULL,
'downtime' => NULL,
'averagePaymentTime' => NULL,
'logoId' => NULL,
'logoPath' => NULL,
'userLogin' => 'elefant',
'category' => NULL,
'countries' => NULL,
'ignoreIPs' => NULL,
'requester' =>
TPerformant\API\HTTP\Affiliate::__set_state(array(
'accessToken' =>
array (
0 => 'notrelevant',
),
'clientToken' =>
array (
0 => 'notrelevant',
),
'uid' =>
array (
0 => 'notrelevant',
),
'userData' =>
TPerformant\API\Model\Affiliate::__set_state(array(
'id' => 8917,
'email' => 'notrelevant',
'login' => 'notrelevant',
'name' => 'notrelevant',
'role' => 'affiliate',
'uniqueCode' => 'notrelevant',
'createdAt' => '2012-04-17T10:25:11Z',
'avatarUrl' => 'https://secure.gravatar.com/avatar/2aa7cbeda20ce7dee64a2764004ef7b5?d=https://network.2performant.com%2Fimg%2Favatar-default.jpg',
'newsletterSubscription' => true,
'userInfo' =>
stdClass::__set_state(array(
'address' => 'Bucuresti',
'city' => 'Bucuresti',
'country' => 'Romania',
'display_name' => 'regular',
'firstname' => 'Andrei',
'lastname' => 'Ioniță',
'organization' => '',
'phone' => '',
'state' => 'Bucuresti',
'typeofbusiness' => '',
)),
'requester' => NULL,
)),
)),
)),
'publicActionData' =>
stdClass::__set_state(array(
'created_at' => '2016-12-24T16:48:07Z',
'updated_at' => '2016-12-24T16:48:07Z',
'rate' => '7.0',
'amount' => '4.41',
'ad_type' => 'quicklink',
'ad_id' => '882',
'source_ip' => '109.99.30.73',
'description' => 'cosmetics|Mascara Extra Super Lash Curved Brush 8 mlx1 (7% from 6.66), cosmetics|Sampon uscat Blush Dry 50 mlx1 (7% from 8.33), cosmetics|Crema de maini si corp cu Lavandax1 (7% from 4.99)',
'working_currency_code' => 'RON',
'amount_in_working_currency' => '19.98',
)),
'publicClickData' =>
stdClass::__set_state(array(
'created_at' => '2016-12-24T16:13:20Z',
'source_ip' => '109.99.30.73',
'url' => 'https://www.maller.ro/voucher-elefant-ro-40-reducere/',
'redirect_to' => 'http://www.elefant.ro/oferte-speciale#utm_source=2parale&utm_medium=Campaign&utm_campaign=2c42f3c4e',
'stats_tags' => ',undefinedDesktopnulla60949bd-0b06-4fd6-a324-0d65351c10e9,',
)),
'requester' =>
TPerformant\API\HTTP\Affiliate::__set_state(array(
'accessToken' =>
array (
0 => 'notrelevant',
),
'clientToken' =>
array (
0 => 'notrelevant',
),
'uid' =>
array (
0 => 'notrelevant',
),
'userData' =>
TPerformant\API\Model\Affiliate::__set_state(array(
'id' => 8917,
'email' => 'notrelevant',
'login' => 'notrelevant',
'name' => 'Andrei Ioniță',
'role' => 'affiliate',
'uniqueCode' => 'notrelevant',
'createdAt' => '2012-04-17T10:25:11Z',
'avatarUrl' => 'https://secure.gravatar.com/avatar/2aa7cbeda20ce7dee64a2764004ef7b5?d=https://network.2performant.com%2Fimg%2Favatar-default.jpg',
'newsletterSubscription' => true,
'userInfo' =>
stdClass::__set_state(array(
'address' => 'Bucuresti',
'city' => 'Bucuresti',
'country' => 'Romania',
'display_name' => 'regular',
'firstname' => 'Andrei',
'lastname' => 'Ioniță',
'organization' => '',
'phone' => '',
'state' => 'Bucuresti',
'typeofbusiness' => '',
)),
'requester' => NULL,
)),
)),
)),

How to sort array based on VERY deep key value

I have this array:
array(
(int) 0 => array(
'Inscricao' => array(
'id' => '89560',
'codigo' => null,
'aluno_id' => '28065',
'turma_id' => '14377',
'estado_inscricao_id' => '13',
'nota_frequencia' => '12.00',
'nota_final' => '10.75',
'epoca_avaliacao_id' => null,
'data' => '2014-02-10',
'created' => '2015-08-31 07:12:42',
'modified' => '2015-09-02 01:31:00',
'matricula_id' => '136247',
'created_by' => null,
'modified_by' => null,
'pagamento_id' => null,
'tipo_inscricao_id' => '1',
'nota_exame_normal' => '9.50',
'nota_exame_recorrencia' => null,
'estado_inscricao' => '2',
'turma_inscricao_id' => null,
'turma_frequencia_id' => '14377'
),
'Turma' => array(
'id' => '14377',
'ano_lectivo_id' => '30',
'curso_id' => '18',
'plano_estudo_id' => '91',
'turno_id' => null,
'disciplina_id' => '394',
'capacidade_maxima' => null,
'total_aprovados' => null,
'media_turma' => null,
'estado_turma_id' => '1',
'modified' => '2015-08-31 07:02:54',
'created' => '2015-08-31 07:02:54',
'total_reprovados' => null,
'codigo' => '2011',
'ano_curricular' => '2',
'semestre_curricular' => '2',
'name' => 'Sociologia do Desporto - 2014 - Licenciatura em Ciências do Desporto - 2011',
'semestre_lectivo_id' => '66',
'sala_aula_id' => null,
'sequencia' => null,
'peso_nota_frequencia' => null,
'peso_nota_exame' => null,
'nota_minima_frequencia' => null,
'nota_minima_dispensa' => null,
'created_by' => null,
'modified_by' => null,
'pauta_path' => null,
'total_alunos' => '44',
'AnoLectivo' => array(
'id' => '30',
'codigo' => '2014',
'ano' => '2014',
'num_semestre' => null,
'data_inicio' => null,
'data_fim' => null,
'created' => '2013-10-08 05:13:51',
'modified' => '2013-10-08 05:13:51',
'regime_lectivo_id' => null
),
'Curso' => array(
'name' => 'Licenciatura em Ciências do Desporto'
),
'Turno' => array(),
'Disciplina' => array(
'id' => '394',
'name' => 'Sociologia do Desporto',
'codigo' => 'SOD',
'codigo_antigo' => null,
'created' => '1432892405',
'modified' => '1432892405',
'created_by' => '54193',
'modified_by' => null,
'unidade_organica_id' => null
)
),
'EstadoInscricao' => array(
'id' => '13',
'name' => 'Aprovado sem Exames'
),
'Matricula' => array(
'id' => '136247',
'codigo' => '',
'aluno_id' => '28065',
'curso_id' => '18',
'plano_estudo_id' => '91',
'data' => '2013-10-30',
'estado_matricula_id' => '1',
'modified' => '2015-08-31 06:55:53',
'created' => '2013-10-31 12:09:43',
'user_id' => '1',
'ano_lectivo_id' => '30',
'turno_id' => '1',
'nivel' => null,
'created_by' => '1',
'modified_by' => null,
'tipo_matricula_id' => '2',
'regime_lectivo_id' => null,
'financeiro_pagamento_id' => null,
'Aluno' => array(
'id' => '28065',
'codigo' => '20115466',
'user_id' => '28066',
'data_ingresso' => '1900-01-01',
'trabalhador' => null,
'area_trabalho_id' => null,
'instituicao_id' => null,
'curso_id' => '18',
'created' => '2011-03-02 14:15:30',
'modified' => '2015-08-31 06:55:52',
'entidade_id' => '28066',
'numero_estudante' => '20115466',
'aluno_via_admissao_id' => '13',
'numero_candidato' => null,
'ano_ingresso' => '2011',
'curso_ingresso_id' => '18',
'created_by' => null,
'modified_by' => null,
'nome_encarregado' => null,
'parentesco_encarregado' => null,
'telefone_encarregado' => null,
'telemovel_encarregado' => null,
'nome_emergencia' => null,
'telefone_emergencia' => null,
'telemovel_emergencia' => null,
'estado_aluno_id' => '1',
'plano_estudo_id' => '91',
'data_conclusao' => null,
'nota_conclusao' => null,
'certificado_nivel_anterior' => '1',
'recenseamento_militar' => '1',
'referencia_renovacao' => null,
'Entidade' => array(
'id' => '28066',
'name' => 'Elisa Luis Artur',
'nome_pai' => 'Luís Artur Vasco',
'nome_mae' => 'Jacinta António',
'foto' => '20115466.jpg',
'genero_id' => '2',
'pais_nascimento' => '152',
'cidade_morada' => null,
'bairro_morada' => null,
'caixa_postal_morada' => null,
'cidade_ferias' => null,
'cidade_nascimento' => '809',
'provincia_nascimento' => null,
'email' => '',
'telefone' => '',
'telemovel' => '825507722',
'documento_identificacao_id' => null,
'documento_identificacao_numero' => null,
'data_nascimento' => '1988-09-20',
'documento_identificacao_data_emissao' => null,
'estado_entidade_id' => null,
'created' => '2011-03-02 14:15:30',
'modified' => '2013-09-13 10:31:17',
'user_id' => '28066',
'documento_identificacao_local_emissao' => null,
'apelido' => 'Artur',
'nomes' => 'Elisa Luis ',
'created_by' => null,
'modified_by' => null,
'provincia_ferias' => null,
'telefone_ferias' => null,
'telemovel_ferias' => null,
'avenida_rua' => null,
'avenida_rua_ferias' => null,
'agregado_familiar_numero' => null,
'estado_civil' => '1',
'documento_identificacao_data_validade' => null,
'nacionalidade' => '1',
'codigo' => '41446',
'naturalidade' => null,
'nuit' => null,
'User' => array(
'password' => '*****',
'id' => '28066',
'username' => 'elisa.artur#uem.ac.mz',
'codigocartao' => '20115466',
'group_id' => '3',
'created_by' => null,
'modified_by' => null,
'ultimo_login' => null,
'codigo_activacao' => '1',
'estado_objecto_id' => '1',
'verificar_permissoes' => '0',
'created' => null,
'modified' => null,
'estado_email' => '0',
'timezone' => null,
'facebook_id' => null
)
)
)
)
),
(int) 1 => array(
'Inscricao' => array(
'id' => '92162',
'codigo' => null,
'aluno_id' => '28446',
'turma_id' => '14377',
'estado_inscricao_id' => '10',
'nota_frequencia' => '10.00',
'nota_final' => '9.75',
'epoca_avaliacao_id' => null,
'data' => '2014-02-11',
'created' => '2015-08-31 07:31:54',
'modified' => '2015-09-02 01:31:00',
'matricula_id' => '130681',
'created_by' => null,
'modified_by' => null,
'pagamento_id' => null,
'tipo_inscricao_id' => '1',
'nota_exame_normal' => '9.50',
'nota_exame_recorrencia' => null,
'estado_inscricao' => '2',
'turma_inscricao_id' => null,
'turma_frequencia_id' => '14377'
),
'Turma' => array(
'id' => '14377',
'ano_lectivo_id' => '30',
'curso_id' => '18',
'plano_estudo_id' => '91',
'turno_id' => null,
'disciplina_id' => '394',
'capacidade_maxima' => null,
'total_aprovados' => null,
'media_turma' => null,
'estado_turma_id' => '1',
'modified' => '2015-08-31 07:02:54',
'created' => '2015-08-31 07:02:54',
'total_reprovados' => null,
'codigo' => '2011',
'ano_curricular' => '2',
'semestre_curricular' => '2',
'name' => 'Sociologia do Desporto - 2014 - Licenciatura em Ciências do Desporto - 2011',
'semestre_lectivo_id' => '66',
'sala_aula_id' => null,
'sequencia' => null,
'peso_nota_frequencia' => null,
'peso_nota_exame' => null,
'nota_minima_frequencia' => null,
'nota_minima_dispensa' => null,
'created_by' => null,
'modified_by' => null,
'pauta_path' => null,
'total_alunos' => '44',
'AnoLectivo' => array(
'id' => '30',
'codigo' => '2014',
'ano' => '2014',
'num_semestre' => null,
'data_inicio' => null,
'data_fim' => null,
'created' => '2013-10-08 05:13:51',
'modified' => '2013-10-08 05:13:51',
'regime_lectivo_id' => null
),
'Curso' => array(
'name' => 'Licenciatura em Ciências do Desporto'
),
'Turno' => array(),
'Disciplina' => array(
'id' => '394',
'name' => 'Sociologia do Desporto',
'codigo' => 'SOD',
'codigo_antigo' => null,
'created' => '1432892405',
'modified' => '1432892405',
'created_by' => '54193',
'modified_by' => null,
'unidade_organica_id' => null
)
),
'EstadoInscricao' => array(
'id' => '10',
'name' => 'Reprovado'
),
'Matricula' => array(
'id' => '130681',
'codigo' => '',
'aluno_id' => '28446',
'curso_id' => '97',
'plano_estudo_id' => null,
'data' => '2013-10-17',
'estado_matricula_id' => '1',
'modified' => '2014-01-13 10:22:24',
'created' => '2013-10-17 11:18:10',
'user_id' => '1',
'ano_lectivo_id' => '30',
'turno_id' => '2',
'nivel' => null,
'created_by' => '1',
'modified_by' => null,
'tipo_matricula_id' => '2',
'regime_lectivo_id' => null,
'financeiro_pagamento_id' => null,
'Aluno' => array(
'id' => '28446',
'codigo' => '20116158',
'user_id' => '28447',
'data_ingresso' => '1900-01-01',
'trabalhador' => null,
'area_trabalho_id' => null,
'instituicao_id' => null,
'curso_id' => '97',
'created' => '2011-03-25 10:07:04',
'modified' => '2013-06-16 22:17:58',
'entidade_id' => '28447',
'numero_estudante' => '20116158',
'aluno_via_admissao_id' => '13',
'numero_candidato' => null,
'ano_ingresso' => '2012',
'curso_ingresso_id' => '18',
'created_by' => null,
'modified_by' => null,
'nome_encarregado' => null,
'parentesco_encarregado' => null,
'telefone_encarregado' => null,
'telemovel_encarregado' => null,
'nome_emergencia' => null,
'telefone_emergencia' => null,
'telemovel_emergencia' => null,
'estado_aluno_id' => '1',
'plano_estudo_id' => null,
'data_conclusao' => null,
'nota_conclusao' => null,
'certificado_nivel_anterior' => '1',
'recenseamento_militar' => '1',
'referencia_renovacao' => null,
'Entidade' => array(
'id' => '28447',
'name' => 'Paulo José Pelembe',
'nome_pai' => 'Mundau José Pelembe',
'nome_mae' => 'Rosa Fomo',
'foto' => '20116158.jpg',
'genero_id' => '1',
'pais_nascimento' => '152',
'cidade_morada' => null,
'bairro_morada' => null,
'caixa_postal_morada' => null,
'cidade_ferias' => null,
'cidade_nascimento' => '1101',
'provincia_nascimento' => null,
'email' => '',
'telefone' => '',
'telemovel' => '828352330',
'documento_identificacao_id' => null,
'documento_identificacao_numero' => null,
'data_nascimento' => '1976-12-17',
'documento_identificacao_data_emissao' => null,
'estado_entidade_id' => null,
'created' => '2011-03-25 10:07:03',
'modified' => '2013-09-13 10:37:47',
'user_id' => '28447',
'documento_identificacao_local_emissao' => null,
'apelido' => 'Pelembe',
'nomes' => 'Paulo José ',
'created_by' => null,
'modified_by' => null,
'provincia_ferias' => null,
'telefone_ferias' => null,
'telemovel_ferias' => null,
'avenida_rua' => null,
'avenida_rua_ferias' => null,
'agregado_familiar_numero' => null,
'estado_civil' => '1',
'documento_identificacao_data_validade' => null,
'nacionalidade' => '1',
'codigo' => '41832',
'naturalidade' => null,
'nuit' => null,
'User' => array(
'password' => '*****',
'id' => '28447',
'username' => 'paulo.pelembe#uem.ac.mz',
'codigocartao' => '20116158',
'group_id' => '3',
'created_by' => null,
'modified_by' => null,
'ultimo_login' => null,
'codigo_activacao' => '1',
'estado_objecto_id' => '1',
'verificar_permissoes' => '0',
'created' => null,
'modified' => null,
'estado_email' => '0',
'timezone' => null,
'facebook_id' => null
)
)
)
)
),
(int) 2 => array(
'Inscricao' => array(
'id' => '92200',
'codigo' => null,
'aluno_id' => '28504',
'turma_id' => '14377',
'estado_inscricao_id' => '13',
'nota_frequencia' => '10.00',
'nota_final' => '10.25',
'epoca_avaliacao_id' => null,
'data' => '2014-02-10',
'created' => '2015-08-31 07:32:17',
'modified' => '2015-09-02 01:31:00',
'matricula_id' => '141228',
'created_by' => null,
'modified_by' => null,
'pagamento_id' => null,
'tipo_inscricao_id' => '1',
'nota_exame_normal' => '8.50',
'nota_exame_recorrencia' => '10.50',
'estado_inscricao' => '2',
'turma_inscricao_id' => null,
'turma_frequencia_id' => '14377'
),
'Turma' => array(
'id' => '14377',
'ano_lectivo_id' => '30',
'curso_id' => '18',
'plano_estudo_id' => '91',
'turno_id' => null,
'disciplina_id' => '394',
'capacidade_maxima' => null,
'total_aprovados' => null,
'media_turma' => null,
'estado_turma_id' => '1',
'modified' => '2015-08-31 07:02:54',
'created' => '2015-08-31 07:02:54',
'total_reprovados' => null,
'codigo' => '2011',
'ano_curricular' => '2',
'semestre_curricular' => '2',
'name' => 'Sociologia do Desporto - 2014 - Licenciatura em Ciências do Desporto - 2011',
'semestre_lectivo_id' => '66',
'sala_aula_id' => null,
'sequencia' => null,
'peso_nota_frequencia' => null,
'peso_nota_exame' => null,
'nota_minima_frequencia' => null,
'nota_minima_dispensa' => null,
'created_by' => null,
'modified_by' => null,
'pauta_path' => null,
'total_alunos' => '44',
'AnoLectivo' => array(
'id' => '30',
'codigo' => '2014',
'ano' => '2014',
'num_semestre' => null,
'data_inicio' => null,
'data_fim' => null,
'created' => '2013-10-08 05:13:51',
'modified' => '2013-10-08 05:13:51',
'regime_lectivo_id' => null
),
'Curso' => array(
'name' => 'Licenciatura em Ciências do Desporto'
),
'Turno' => array(),
'Disciplina' => array(
'id' => '394',
'name' => 'Sociologia do Desporto',
'codigo' => 'SOD',
'codigo_antigo' => null,
'created' => '1432892405',
'modified' => '1432892405',
'created_by' => '54193',
'modified_by' => null,
'unidade_organica_id' => null
)
),
'EstadoInscricao' => array(
'id' => '13',
'name' => 'Aprovado sem Exames'
),
'Matricula' => array(
'id' => '141228',
'codigo' => '',
'aluno_id' => '28504',
'curso_id' => '18',
'plano_estudo_id' => '91',
'data' => '2013-10-31',
'estado_matricula_id' => '1',
'modified' => '2015-08-31 06:56:21',
'created' => '2013-11-01 07:56:44',
'user_id' => '1',
'ano_lectivo_id' => '30',
'turno_id' => '1',
'nivel' => null,
'created_by' => '1',
'modified_by' => null,
'tipo_matricula_id' => '2',
'regime_lectivo_id' => null,
'financeiro_pagamento_id' => null,
'Aluno' => array(
'id' => '28504',
'codigo' => '20116434',
'user_id' => '28505',
'data_ingresso' => '1900-01-01',
'trabalhador' => null,
'area_trabalho_id' => null,
'instituicao_id' => null,
'curso_id' => '18',
'created' => '2011-03-28 12:12:43',
'modified' => '2015-08-31 06:56:21',
'entidade_id' => '28505',
'numero_estudante' => '20116434',
'aluno_via_admissao_id' => '13',
'numero_candidato' => null,
'ano_ingresso' => '2011',
'curso_ingresso_id' => '18',
'created_by' => null,
'modified_by' => null,
'nome_encarregado' => null,
'parentesco_encarregado' => null,
'telefone_encarregado' => null,
'telemovel_encarregado' => null,
'nome_emergencia' => null,
'telefone_emergencia' => null,
'telemovel_emergencia' => null,
'estado_aluno_id' => '1',
'plano_estudo_id' => '91',
'data_conclusao' => null,
'nota_conclusao' => null,
'certificado_nivel_anterior' => '1',
'recenseamento_militar' => '1',
'referencia_renovacao' => null,
'Entidade' => array(
'id' => '28505',
'name' => 'Lina Mário Matola',
'nome_pai' => 'Mário Augusto Matola',
'nome_mae' => 'Lina Albino Manjate',
'foto' => '20116434.jpg',
'genero_id' => '2',
'pais_nascimento' => '152',
'cidade_morada' => null,
'bairro_morada' => null,
'caixa_postal_morada' => null,
'cidade_ferias' => null,
'cidade_nascimento' => '1101',
'provincia_nascimento' => null,
'email' => 'linamario16#yahoo.com.br ',
'telefone' => '',
'telemovel' => '828322450',
'documento_identificacao_id' => null,
'documento_identificacao_numero' => null,
'data_nascimento' => '1988-04-13',
'documento_identificacao_data_emissao' => null,
'estado_entidade_id' => null,
'created' => '2011-03-28 12:12:42',
'modified' => '2013-09-13 10:38:41',
'user_id' => '28505',
'documento_identificacao_local_emissao' => null,
'apelido' => 'Matola',
'nomes' => 'Lina Mário',
'created_by' => null,
'modified_by' => null,
'provincia_ferias' => null,
'telefone_ferias' => null,
'telemovel_ferias' => null,
'avenida_rua' => null,
'avenida_rua_ferias' => null,
'agregado_familiar_numero' => null,
'estado_civil' => '1',
'documento_identificacao_data_validade' => null,
'nacionalidade' => '1',
'codigo' => '41891',
'naturalidade' => null,
'nuit' => null,
'User' => array(
'password' => '*****',
'id' => '28505',
'username' => 'lina.matola#uem.ac.mz',
'codigocartao' => '20116434',
'group_id' => '3',
'created_by' => null,
'modified_by' => null,
'ultimo_login' => null,
'codigo_activacao' => '1',
'estado_objecto_id' => '1',
'verificar_permissoes' => '0',
'created' => null,
'modified' => null,
'estado_email' => '0',
'timezone' => null,
'facebook_id' => null
)
)
)
)
),
(int) 3 => array(
and I want to sort this based on key "apelido". What is the best way to do this in PHP?
Note: the Key apelido is in [0]['Matricula']['Aluno']['Entidade']['apelido'].
NOTE 2: This is a result of CakePHP find with Containable. Is there a way that cake could sort it during find?
Use Hash::sort(), it accepts a path in Hash path syntax format, allowing to specify deeply nested paths.
$sorted = Hash::sort($data, '{n}.Matricula.Aluno.Entidade.apelido');
Further arguments define the sort order, and the sort type, see Cookbook > Core Libraries > Utilities > Hash > Hash::sort() for more information.
If you want to have this being returned sorted by the find call, you could for example modify the results in the Model::afterFind() callback, or in a custom finder, see
Cookbook > Models > Callback Methods > afterFind
Cookbook > Models > Retrieving Your Data > Creating custom find types

Accessing arrays and or objects

*I solved it myself... like 10 minutes later. *
$varbgimg = $row->_field_data['nid']['entity']->field_slideimage['und'][0]['uri'];
Is what I used...
Hope someone can help me. How can I access 'uri' => 'public://veglo8.jpg'?
This is from Drupal and the Views module. If someone could maybe even help me with my ultimate goal, I would appreciate that...
I have a field in Views called slideimage. I want to add a style="background-image:url(image field URL);" to my div. Tried to rewrite the output but it strips the style...
Thanks in advance.
stdClass::__set_state(array(
'nid' => '20',
'node_title' => 'Test 1',
'field_data_field_slideimage_node_entity_type' => 'node',
'field_data_body_node_entity_type' => 'node',
'_field_data' =>
array (
'nid' =>
array (
'entity_type' => 'node',
'entity' =>
stdClass::__set_state(array(
'vid' => '20',
'uid' => '1',
'title' => 'Test 1',
'log' => '',
'status' => '1',
'comment' => '1',
'promote' => '0',
'sticky' => '0',
'nid' => '20',
'type' => 'test',
'language' => 'und',
'created' => '1358336066',
'changed' => '1358337923',
'tnid' => '0',
'translate' => '0',
'revision_timestamp' => '1358337923',
'revision_uid' => '1',
'body' =>
array (
'und' =>
array (
0 =>
array (
'value' => 'Body text here',
'summary' => '',
'format' => 'filtered_html',
'safe_value' => '
Body text here',
'safe_summary' => '',
),
),
),
'field_slideimage' =>
array (
'und' =>
array (
0 =>
array (
'fid' => '8',
'alt' => '',
'title' => '',
'width' => '624',
'height' => '390',
'uid' => '1',
'filename' => 'veglo8.jpg',
'uri' => 'public://veglo8.jpg',
'filemime' => 'image/jpeg',
'filesize' => '27393',
'status' => '1',
'timestamp' => '1358336725',
'rdf_mapping' =>
You can use file_create_url to convert public://... to real world URLs.
$real_url = file_create_url($img_src);
I've used the pathinfo() function for this in the past.
http://php.net/manual/en/function.pathinfo.php
You can apply styles programmatically with this by replacing user-picture[0]['uri'] with your image url. I think you can even place the whole public:// url in there and it will work just fine as well.
THUMBNAIL_STYLE = 'thumbnail';
// now get the full image url from the uri and the style
$default_thumbnail = image_style_url($THUMBNAIL_STYLE, $user->picture[0]['uri']);
http://drupal.org/node/1425836

Categories