0

I have a PHP code which collect data from user´s input based on a range of given options (Banks).

*Piece of code:

$domElement = $domDocument->createElement('attribute', $posted_data['bank']);

Conversion table:

enter image description here

Thus, if user select CITIBANK, it should return "001" into my code and not CITIBNAK itself. This should be applied for all the others choices.

What would be the best way to do it?
By using array or "if statement conditions" or even other solution?

8
  • Use a dropdown menu with the code in the value attribute and the name in the text. Commented Jul 19, 2018 at 1:59
  • <option value="001">Citibank</option> Commented Jul 19, 2018 at 2:00
  • Can't do it, cause the value is already set as "Bank" (this line code is not included in the post) Commented Jul 19, 2018 at 2:01
  • Then I don't understand the question. Are you just asking how to create an associative array that translates the bank name to the code number? Commented Jul 19, 2018 at 2:07
  • array('CITIBANK' => '001', 'BANK BOSTON' => '002', ...) Commented Jul 19, 2018 at 2:08

1 Answer 1

1

Use an associative array:

$bank_numbers = array('CITIBANK' => '001', 'BANK BOSTON' => '002', ...);
$banknum = $bank_numbers[$posted_data['bank']];
$domElement = $domDocument->createElement('attribute', $banknum);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.