0

$def_field = array(
	"def_value" => 'Display Name',
	"def_value" => 'Database Value'
);

Here i have a array in that i need to assign both Display Name and Database Value to def_value key. how to do that can anyone please help me..

1
  • How does your output look like? Commented May 22, 2020 at 4:06

2 Answers 2

2

Your way is incorrect as the second index will override the first index value because they have the same name. So You will have only this in your array:

$def_field = array(
    "def_value" => 'Database Value'
);

You can do it these ways

$def_field = array(
  "def_value" => array('Display Name','Database Value')
);

Or like this:

$def_field = [];
$def_field['def_value'][] = 'Display Name';
$def_field['def_value'][] = 'Database Value';

The second exemple kind of explains everything. You will create an array with index $def_value inside array $def_field with values 'Display Name' having index 0 and 'Database Value' having index 1.

Sign up to request clarification or add additional context in comments.

Comments

0

You will probably need to add it as a nested array like this:

$def_field = array(
    "def_value" => array('Display Name','Database Value')
);

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.