Jump to content

anand0412

New Members
  • Posts

    8
  • Joined

  • Last visited

anand0412's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you for the clarification. I truly appreciate your help here.
  2. Hi @mac_gyver, I'm sorry if this is a noob question. I'm trying to understand this code. What is the purpose of the line 2 code - $params = []; what happens if I remove line 2? Thank you.
  3. Thank you. I didn't know what a splat operator was. Your solution is perfect.
  4. Hi. Thanks for the suggestion and effort. However, I tried it and it threw an error. Maybe if I give my full function it would be more helpful :- function SpecificGifts ( $benfield , $propcat , $proptype , $proppost , $titledet , $MOGM , $FSG , $VDesc , $Vreg , $Jdesc , $ODesc ) { if ( is_array( $benfield ) ){ echo '<li>'; if ( count( $benfield ) == 1) { $beneficiaries = (implode(', ', $benfield)) . '.'; } elseif (count( $benfield ) > 1 ) { $beneficiaries = (implode(', ', $benfield)) ; $beneficiaries = preg_replace("/,([^,]+)$/", " and $1", $beneficiaries) . ' equally.' ; } Switch ($proptype) { case 'Immovable Property (Land / House)': return 'My ' . $propcat . ' bearing postal address ' . $proppost . ' held under '. $titledet . ' to ' . $beneficiaries ; break; case 'Money' : if ($MOGM = 'All My Money') { return 'All my money to ' . $beneficiaries ; } elseif ($MOGM = 'A Fixed Sum of Money') { return '<li> A sum of ' . $FSG . ' to ' . $beneficiaries ; } case 'Vehicle' : return 'My ' . $VDesc . ' bearing registration number ' . $Vreg . ' to ' . $beneficiaries ; break; case 'Jewellery' : return $Jdesc . ' to ' . $beneficiaries ; break; case 'Others' : return $ODesc . ' to ' . $beneficiaries ; break; } echo '</li>'; } } $gift_fields = [77, 80, 65, 66, 67, 83, 74, 87, 88, 90, 92]; $params = []; foreach($gift_fields as $field){ $params[] = $form_data['field'][$field]; } echo SpecificGifts($params); data field is the data from gravity form.
  5. Hi all. I have a function like this function SpecificGifts ( $benfield , $propcat , $proptype , $proppost , $titledet , $MOGM , $FSG , $VDesc , $Vreg , $Jdesc , $ODesc ) { //code ; } I then call the function like this echo SpecificGifts ( $form_data['field'][77] , $form_data['field'][80] , $form_data['field'][65] , $form_data['field'][66] , $form_data['field'][67] , $form_data['field'][83] , $form_data['field'][74] , $form_data['field'][87] , $form_data['field'][88] , $form_data['field'][90] , $form_data['field'][92]); Is there a way i can write this more elegant and simpler format? Thanks in advance.
  6. Awesome. That worked. Thank you very very much. I can finally sleep peacefully tonight.
  7. Thank you for pointing it out. Thanks for the suggestion. I have implemented both your suggestions. For some reason I am still not getting any result. my new code is now function GetBeneficiaries ( $benfield ) { if ( is_array( $form_data['field'][$benfield] ) AND count( $form_data['field'][$benfield] ) == 1 ) { $beneficiaries = ' to ' . (implode(', ', $form_data['field'][$benfield])) . '.'; return $beneficiaries; } elseif ( is_array( $form_data['field'][$benfield] ) AND count( $form_data['field'][$benfield] ) > 1 ) { $beneficiaries = (implode(', ', $form_data['field'][$benfield])); $beneficiaries = 'to ' . substr_replace($beneficiaries, ' and', strrpos($beneficiaries, ','), 1) . ' equally.'; return $beneficiaries; } } echo GetBeneficiaries ( 77 ); I have been at this for 2 days now. I appreciate your help
  8. Hi all. I have no formal education in programming and learning everything through internet. Forgive me if this is too basic. I am creating a automated document from gravity forms in wordpress. This is the example of code that works. if ( is_array( $form_data['field'][77] ) AND count( $form_data['field'][77] ) == 1 ) { $v_bop1 = ' to ' . (implode(', ', $form_data['field'][77])) . '.'; } elseif ( is_array( $form_data['field'][77] ) AND count( $form_data['field'][77] ) > 1 ) { $v_bop1 = (implode(', ', $form_data['field'][77])); $v_bop1 = 'to ' . substr_replace($v_bop1, ' and', strrpos($v_bop1, ','), 1) . ' equally.'; } As you may have guessed, I am trying to get some data from gravity form and reformat it to suit my document. However, in order to work, I need to duplicate this code for each and every entry which seems inefficient. I tried to create a function using this code:- function GetBeneficiaries ( $benfield ) { if ( is_array( $form_data['field'][$benfield] ) AND count( $form_data['field'][benfield] ) == 1 ) { $beneficiaries = ' to ' . (implode(', ', $form_data['field'][benfield])) . '.'; } elseif ( is_array( $form_data['field'][benfield] ) AND count( $form_data['field'][benfield] ) > 1 ) { $beneficiaries = (implode(', ', $form_data['field'][benfield])); $beneficiaries = 'to ' . substr_replace($beneficiaries, ' and', strrpos($beneficiaries, ','), 1) . ' equally.'; echo $beneficiaries; } } I should then be able to call the function with GetBeneficiaries ( 77 ); However, my function is not returning any data / value. What am I doing wrong?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.