How to get the value from array php - php

Here is my value for print_r($_GET);
the Output is
Array(
[prevurl() ] => Array(
[taxirate] => 3500[Source] => Land[T] => Yes[TId] => 10[dtaxirate] => 4500[TD] => Yes[TDId] => 14[modeset] => minivan[minivanrate] => 400[Minivan] => Yes[MinivanId] => 6[FirstSearch] => FirstSearch[returnTrip] => yes[return -one] => No[Trip] => OneWay[TravelFrom] => Destination[TravelTo] => Pak[TravelDay] => 2015 - 08 - 16[TotalCount] => 1[Mode] => [Both] => [BothReturn] => 2015 - 08 - 17[Adults] => 1[Childs] => [Kids] => [Babies] =>
)
)
I tried
echo $_GET['prevurl']['taxirate']; but it is not working.
How can i get the value of taxirate
<input type="hidden" value="Array
(
[taxirate] => 3500
[Source] => Land
[T] => Yes
[TId] => 10
[dtaxirate] => 4500
[TD] => Yes
[TDId] => 14
[modeset] => minivan
[minivanrate] => 400
[Minivan] => Yes
[MinivanId] => 6
[FirstSearch] => FirstSearch
[returnTrip] => yes
[return-one] => No
[Trip] => OneWay
[TravelFrom] => Hat Yai Airport
[TravelTo] => Pak Bara
[TravelDay] => 2015-08-16
[TotalCount] => 1
[Mode] =>
[Both] =>
[BothReturn] => 2015-08-17
[Adults] => 1
[Childs] =>
[Kids] =>
[Babies] =>
)
" name="prevurl">
Update :
Note :
Here is my input in the previous page
<input type="hidden" value="Array
(
[taxirate] => 3500
[Source] => Land
[T] => Yes
[TId] => 10
[dtaxirate] => 4500
[TD] => Yes
[TDId] => 14
[modeset] => minivan
[minivanrate] => 400
[Minivan] => Yes
[MinivanId] => 6
[FirstSearch] => FirstSearch
[returnTrip] => yes
[return-one] => No
[Trip] => OneWay
[TravelFrom] => Hat Yai Airport
[TravelTo] => Pak Bara
[TravelDay] => 2015-08-16
[TotalCount] => 1
[Mode] =>
[Both] =>
[BothReturn] => 2015-08-17
[Adults] => 1
[Childs] =>
[Kids] =>
[Babies] =>
)
" name="prevurl()">
Actually the input was an array

Assuming the array value is stored in a variable, I would try:
<?php
foreach ($array_data as $key=>$value)
{
if($key == "prevurl")
{
foreach ($value as $key1=>$value1)
{
switch($key1)
{
case "taxirate":
$taxirate = $value1;
break;
}
}
}
}
?>
But I agree with Rasclatt. That array is odd looking/something weird with it.
Edit: Your original question looked like a multidimensional array, but your edit doesn't look multidimensional. My answer was from your original code.

just change your hidden input fields name to name="prevurl". And get your value of taxirate as:
$_GET['prevurl']['taxirate'];

Related

Multiply data in array

I'm keeping data in Array, I want to multiply these data with each other, but I was not successful. I found the Array_product function but I could not run it successfully. What do you think the problem is?
$kuponlar = $_SESSION['kuponlar'];
$maclar = $kuponlar['maclar'];
The data I want to multiply:
echo array_product($maclar['oran']));
array_product does not work when I want to do. Is there a recommendation that the problem could not find?
Array
(
[maclar] => Array
(
[5ca4fb869b043] => stdClass Object
(
[mac_id] => 881
[mac_kod] => 657
[mac_lig] => HIR
[mac_zaman] => 04.04.2019
[mac_saat] => 19:00
[mac_slug] => rudes/istra/657
[mac_handikap] => 1
[ev_logo] => 12644
[deplasman_logo] => 6776
[iddaa_id] => 1308487
[evsahibi] => Rudes
[deplasman] => Istra
[ulke] => Hırvatistan 1. Ligi
[mac_tarihi] => 04.04.2019 19:00:00
[sonuc] =>
[live] => 0
[mac_uniq] => 5ca4fb869b043
[count] => 1
[tahmin] => Ev Kazanır
[oran] => 2.85
[durum] => 0
)
[5ca4fb869bf78] => stdClass Object
(
[mac_id] => 882
[mac_kod] => 658
[mac_lig] => HOL
[mac_zaman] => 04.04.2019
[mac_saat] => 19:30
[mac_slug] => psv/zwolle/658
[mac_handikap] => -1
[ev_logo] => 2836
[deplasman_logo] => 2869
[iddaa_id] => 1306687
[evsahibi] => PSV
[deplasman] => Zwolle
[ulke] => Hollanda Eredivisie Ligi
[mac_tarihi] => 04.04.2019 19:30:00
[sonuc] =>
[live] => 0
[mac_uniq] => 5ca4fb869bf78
[count] => 1
[tahmin] => Ev Kazanır
[oran] => 1.10
[durum] => 0
)
[5ca4fb869cde3] => stdClass Object
(
[mac_id] => 883
[mac_kod] => 660
[mac_lig] => İTA
[mac_zaman] => 04.04.2019
[mac_saat] => 20:00
[mac_slug] => sassuolo/chievo/660
[mac_handikap] =>
[ev_logo] => 665
[deplasman_logo] => 578
[iddaa_id] => 1333704
[evsahibi] => Sassuolo
[deplasman] => Chievo
[ulke] => İtalya Serie A Ligi
[mac_tarihi] => 04.04.2019 20:00:00
[sonuc] =>
[live] => 0
[mac_uniq] => 5ca4fb869cde3
[count] => 1
[tahmin] => Beraberlik
[oran] => 3.20
[durum] => 0
)
)
[summary] => Array
(
[total] => 1
[count] => 0
)
)
You need to multiply the property oran of each object in your array:
$maclar = $kuponlar['maclar'];
$mul = 1;
foreach($maclar as $key => $value){
$mul *= $value->oran;
}
You don't have 'oran' index in $maclar array, at first you should make an array of 'oran' then use array_product on that array.
for example:
foreach($maclar as $key=>$object){
$oran[] = $object->oran;
}
echo array_product($oran);

how to convert data type from result_object codeigniter

I have an array of objects from the query as follows :
Array
(
[0] => stdClass Object
(
[row_number] => 1
[cash_id] => 30938
[closing_id] =>
[is_closed] => 0
[cash_date] => 2018-04-03
[store_id] => 13
[store_code] => 504
[store_account] => ST0013
[store_vendor] => ES0013
[store_dwds] => 01R-0101A006S0013
[store_name] => KARTIKA CHANDRA
[area_id] => 11
[area_code] => A11
[area_name] => Area 11
[region_id] => 1
[region_code] => R01
[region_name] => Region 1
[closing_date] =>
[closing_type] =>
[closing_type_desc] =>
[cash_amount] => 6000000.0000
[closing_amount] =>
[update_time] =>
[update_by_username] =>
[update_by_first_name] =>
[update_by_last_name] =>
[update_by_email] =>
)
[1] => stdClass Object
(
[row_number] => 1
[cash_id] => 30938
[closing_id] =>
[is_closed] => 0
[cash_date] => 2018-04-03
[store_id] => 13
[store_code] => 504
[store_account] => ST0013
[store_vendor] => ES0013
[store_dwds] => 01R-0101A006S0013
[store_name] => KARTIKA CHANDRA
[area_id] => 11
[area_code] => A11
[area_name] => Area 11
[region_id] => 1
[region_code] => R01
[region_name] => Region 1
[closing_date] =>
[closing_type] =>
[closing_type_desc] =>
[cash_amount] => 6000000.0000
[closing_amount] =>
[update_time] =>
[update_by_username] =>
[update_by_first_name] =>
[update_by_last_name] =>
[update_by_email] =>
)
)
how do i change the is_closed object into a boolean data type ?
thanks,
You'll have to cast it to a boolean in your loop when you use it.
array_walk($Result, function ($item) {
$item->is_closed = (bool) $item->is_closed;
});

How do I get values of the email out of this array? [duplicate]

This question already has answers here:
PHP - Accessing Multidimensional Array Values
(4 answers)
Closed 6 years ago.
How do I get values of the email out of this array?
Array
(
[0] => Array
(
[ExamApplication] => Array
(
[id] => 27
[user_id] => 78
[exam_id] => 2
[faculty_id] => 3
[subspeciality_id] => 0
[ref_number] => 14490644320853527823
[exam] =>
[certification] => /files/78/2015-12-02-09-46-40-Dr._Taofeek.jpg
[marriage_certificate] =>
[newspaper_advert] =>
[sworn_affidavit] =>
[other_marriage_evidence] =>
[primary_evidence_cert] =>
[med_school] => LADOKE AKINTOLA UNIVERSITY OF TECHNOLOGY, OGBOMOSO, OYO STATE.
[med_school_address] => P.M.B 4000, OGBOMOSO, OYO STATE
[med_school_year] => 2013
[med_school_cert] =>
[med_school_cert_type] =>
[med_board_year] => 7-11-2014
[med_board_cert] => /files/78/2015-12-02-09-46-40-scan0014.jpg
[med_board_cert_type] =>
[discharge_year] => 3-11-2015
[discharge_type] => NYSC
[discharge_cert] => /files/78/2015-12-02-09-46-40-scan0012.jpg
[discharge_cert_type] =>
[training_cert] =>
[accredition_prog_inst] =>
[accredition_prog_add] =>
[accredition_prog_year] =>
[mbbs_cert] => /files/78/2015-12-02-09-46-40-scan0007.jpg
[logbook] =>
[excemption_cert] =>
[manuscript_cert] =>
[revision_cert] =>
[surgeon_cert] =>
[surgical_cert] =>
[ethics_cert] =>
[exam_date] => 04/2016
[exam_center] => Ibadan
[approval_status] => Approved
[reseat_status] => No
[save_status] => 3
[submitted_date] =>
[exam_number] => 20704160002
[comment] =>
[created] => 2015-12-02 09:46:40
[modified] => 2016-02-22 14:25:12
)
[User] => Array
(
[id] => 78
[email] => tafabny#yahoo.com
[password] => 81e1e0742e4e06c5a13e87000e3f8d201e51dc02
[role] => students
[faculty_id] => 0
[status] => 1
[pass_token] =>
[created] => 2015-12-01 10:32:15
[modified] => 2015-12-01 10:32:15
)
[Exam] => Array
(
[id] => 2
[init] => 1000
[exam] => Primary
[exam_months] => 10
[exam_years] => 2016
[closing] => 2016-08-17
[created] => 0000-00-00 00:00:00
[modified] => 2016-04-23 12:33:54
)
Please how can I get the value of the user email out from the above array?
Hi you can get your array value using below statement
echo $arr[0]['user']['email'];
For more details of array and value use below link
how to get single value from php array

CakePHP - validation returning false

validates() getting failed, but the validationErrors is empty in CakePHP 2.x, even I have user unlockedActions for this method but still getting this error, while inserting its working fine. Only edit is not working.
This my controller code:
if (!empty($this->data['UserProfileName']['new']['new_profile_id'])){
// $this->data['UserProfileName']['old_profile_id'] = $this->data['UserProfileName']['profile_id'];
$new_data['UserProfileName']['profile_id'] = $this->data['UserProfileName']['new']['new_profile_id'];
$new_data['UserProfileName']['user_profile_id']=$userProfileId;
$this->UserProfileName->create();
$this->UserProfileName->set($new_data);
}
$this->UserProfileContact->set($this->data);
if ($this->UserProfileName->validates() && $this->UserProfileContact->validates()) {
} else {
$errors = $this->UserProfileName->validationErrors;
$errors = $this->UserProfileContact->validationErrors;
pr($this->UserProfile->validationErrors);
pr($errors);
}
The form input $this->data is:
Array
(
[UserProfile] => Array
(
[id] => 1
[expiry_date] => 2017-06-30
[is_remarriage] => 0
[is_featured] => 1
[featured_date] => 2015-06-30
[featured_expity_date] => 2015-07-15
[language_id] => 1
[name] => Profile1
[gender_id] => 1
[date_of_birth] => 1988-06-30
[time_of_birth] => Array
(
[hour] => 05
[min] => 11
[meridian] => pm
)
[place_of_birth] => Trichy
[religion_id] => 1
[caste_id] => 3
[sub_caste_id] => 2
[community_id] => 3
[gothram_id] => 3
[star_id] => 5
[rasi_id] => 5
[food_habbit_id] => 2
[height] => 145
[height_type_id] => 1
[weight] => 50
[complexion_id] => 2
[blood_group_id] => 7
[disability_id] =>
[other_disability] =>
[talents] => Singing
[hobbies] => Handicrafts
[languages_konwn] => Tamil, English,Hindi
[qualification_id] => 1
[other_qualification] =>
[employment_type_id] => 5
[job_details] =>
[income] =>
[income_type_id] => 1
[parents_alive_type_id] => 2
[father_name] => Fname
[father_job] => Business
[mother_name] => Mname
[mother_job] => house wife
[mother_caste_id] => 3
[brothers_elder] => 2
[brothers_younger] =>
[brothers_married] => 1
[sisters_elder] =>
[sisters_younger] =>
[sisters_married] =>
[family_status_id] => 2
[marital_status_id] =>
[date_of_marriage] =>
[date_of_divorce] =>
[lived_together_duration] =>
[cilidrean_details] =>
[other_info] =>
[is_show_photo] => 1
)
[UserProfileName] => Array
(
[0] => Array
(
[id] => 1
[profile_id] => Profile1001
)
[new] => Array
(
[new_profile_id] =>
)
)
[PropertyType] => Array
(
[PropertyType] => Array
(
[0] => 1
[1] => 4
)
)
[UserProfileExpectation] => Array
(
[id] => 1
[qualification_id] => 2
[job_requirement_type_id] => 1
[preferred_place_of_job] => With in Tamil nadu
[min_income] => 900000/ann
[caste_id] => 3
[sub_caste_id] => 1
[community_id] => 1
[food_habbit_id] => 2
[marital_status_id] => 1
[is_horoscope_matching_required] => 1
[is_accept_disablity] => 0
[other_expectation] =>
)
[UserProfileHoroscopeDetail] => Array
(
[id] => 1
[balance_dasa_name] => sun
[balance_dasa_years] => 12
[balance_dasa_months] => 9
[balance_dasa_days] => 25
[rasi_1] => sss
[rasi_2] => hggf
[rasi_3] => ffgd
[rasi_4] =>
[rasi_12] =>
[rasi_5] =>
[rasi_11] =>
[rasi_6] => dfgd
[rasi_10] =>
[rasi_9] => fgdfd
ghg
fgf
[rasi_8] =>
[rasi_7] =>
[amsam_1] =>
[amsam_2] => fg
[amsam_3] =>
[amsam_4] =>
[amsam_12] => fghfg
[amsam_5] => fghfg
[amsam_11] => fgf
[amsam_6] =>
[amsam_10] =>
[amsam_9] =>
[amsam_8] => fghf
[amsam_7] =>
)
[UserProfileContact] => Array
(
[email] => jayashree+profile25#jbcs.co.in
[permanent_address] => fhgfhg
[permanent_country_id] => 1
[permanent_zone_id] => 1
[permanent_city_id] => 1
[local_address] =>
[local_country_id] => 1
[local_zone_id] => 1
[local_city_id] => 1
[phone_1] => 2134657898
[phone_2] =>
[phone_3] =>
[phone_4] =>
)
[images] => Array
(
[1] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)
[2] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)
[3] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)
)
)`
It always goes to else part, but when I print the error array it's empty.
Try this and modify according your requirement.
if(!empty($this->data))
{
$this->User->set( $this->data['User'] );
$this->Contractor->set( $this->data['Contractor'] );
if ($this->User->validates() && $this->Contractor->validates())
{
$this->data['User']['passwd'] = $this->Auth->password($this->data['User']['new_passwd']);
$this->data['User']['created'] = date("Y-m-d H:i:s");
$user = $this->data['User'];
$contractor = $this->data['Contractor'];
//pr($this->data);die;
if( $this->User->save( $user ) )
{
$newId = $this->User->getLastInsertId();
$contractor['user_id'] = $newId;
if($this->Contractor->save($contractor))
{
$this->redirect('/contractors/index') ;
}
}
}else{
$this->validateErrors($this->User);
$this->validateErrors($this->Contractor);
$this->render();
}
}
I have solved the issue by change the validation rule
in validation rule i've used
'required' => 'create',
and changed to
'on' => 'create',
now its working.

How to sort same next value in foreach loop using php?

I new to PHP. What I want to do is hide the same data in a foreach loop.
Here is my code:
foreach($recording_record as $row ){
echo $row->criteria_title;
echo $row->question_title;
}
My current interface:
How I want my interface to be:
Here is my print_r data:
Array ( [0] => stdClass Object ( [record_id] => 6 [qm_id] => 2 [qm_title] => QM LEAD 2 [record_filename] => abcdefgh.mp3 [userid] => 1002 [unique_id] => 1325554791.71044 [supervisor_id] => 1000 [date_created] => 2013-05-14 05:29:24 [status] => 3 [id] => 6 [callid] => 1325554791.71044 [callerid] => 0383153394 [queuename] => t1-BM_OE [extension] => SIP/1003 [ivrtime] => 2013-05-14 11:14:36 [queuetime] => 2012-01-03 09:40:33 [connecttime] => 2013-05-09 09:40:36 [disconnecttime] => 2012-01-03 09:46:34 [callduration] => 358 [holdduration] => 0 [queueduration] => 3 [ansduration] => 3 [ringduration] => 0 [lastevent] => COMPLETEAGENT [transfer] => [wrapups] => ,12 [tenantid] => 1 [supervisor] => 1005 [username] => Fara [userpass] => 1234 [lastname] => Binti Johari [firstname] => Nurul Farahhin [userlevel] => 2 [usercreated] => 2011-03-26 23:11:56 [lastlogin] => 2012-10-13 20:17:10 [userexten] => [sessionid] => [userstatusid] => 0 [apptype] => webagent [statustimestamp] => 2012-10-13 20:33:21 [lastuserstatusid] => 1 [pqueuetimeout] => 0 [queueroutetype] => 1 [queueroutevalue] => 4 [userdbstatus] => A [criteria_id] => 1 [criteria_title] => Did not demonstrate inappropriate behavior - Zero Tolerance Policy [criteria_rate] => 40 [question_id] => 4 [question_title] => Question 2 [question_type] => n [question_score_y_yes] => [question_score_y_no] => [question_score_y_answer] => [question_score_y] => [question_score_n_a] => 1 [question_score_n_a_value] => True [question_score_n_b] => 0 [question_score_n_b_value] => False [question_score_n_c] => 0 [question_score_n_c_value] => [question_score_n_d] => 0 [question_score_n_d_value] => [question_score_n_e] => 0 [question_score_n_e_value] => [question_score_n_answer] => [question_score_n] => ) [1] => stdClass Object ( [record_id] => 6 [qm_id] => 2 [qm_title] => QM LEAD 2 [record_filename] => abcdefgh.mp3 [userid] => 1002 [unique_id] => 1325554791.71044 [supervisor_id] => 1000 [date_created] => 2013-05-14 05:29:24 [status] => 3 [id] => 6 [callid] => 1325554791.71044 [callerid] => 0383153394 [queuename] => t1-BM_OE [extension] => SIP/1003 [ivrtime] => 2013-05-14 11:14:36 [queuetime] => 2012-01-03 09:40:33 [connecttime] => 2013-05-09 09:40:36 [disconnecttime] => 2012-01-03 09:46:34 [callduration] => 358 [holdduration] => 0 [queueduration] => 3 [ansduration] => 3 [ringduration] => 0 [lastevent] => COMPLETEAGENT [transfer] => [wrapups] => ,12 [tenantid] => 1 [supervisor] => 1005 [username] => Fara [userpass] => 1234 [lastname] => Binti Johari [firstname] => Nurul Farahhin [userlevel] => 2 [usercreated] => 2011-03-26 23:11:56 [lastlogin] => 2012-10-13 20:17:10 [userexten] => [sessionid] => [userstatusid] => 0 [apptype] => webagent [statustimestamp] => 2012-10-13 20:33:21 [lastuserstatusid] => 1 [pqueuetimeout] => 0 [queueroutetype] => 1 [queueroutevalue] => 4 [userdbstatus] => A [criteria_id] => 1 [criteria_title] => Did not demonstrate inappropriate behavior - Zero Tolerance Policy [criteria_rate] => 40 [question_id] => 3 [question_title] => Question 1 [question_type] => y [question_score_y_yes] => 1 [question_score_y_no] => 0 [question_score_y_answer] => [question_score_y] => [question_score_n_a] => [question_score_n_a_value] => [question_score_n_b] => [question_score_n_b_value] => [question_score_n_c] => [question_score_n_c_value] => [question_score_n_d] => [question_score_n_d_value] => [question_score_n_e] => [question_score_n_e_value] => [question_score_n_answer] => [question_score_n] => )
Any idea how to do it?
$i = 0;
$criteria = array();
foreach($recording_record as $row ){
$criteria[$i] = $row->criteria_title;
if($i > 0){
if ($criteria[$i] != $criteria[$i-1]){
echo $criteria[$i];
}
} else {
echo $criteria[$i];
}
echo $row->question_title;
$i++;
}
Use this
$new_recording_record = array_unique($recording_record);
try this:
echo $recording_record[0]->criteria_title;
foreach($recording_record as $row ){
echo $row->question_title;
}
Check if this works?
$i = 1;
foreach($recording_record as $row ){
$title = $row->criteria_title;
$question_title = $row->question_title;
if($ငငငi==1)
echo $title;
echo $question_title;
$i++;
}

Categories