0

is it possible to use array for internal like this?

$b = array(
  'a' => 'Adam',
  'b' => $b['a'].' and eve'
);
2
  • 4
    No, it's not, because $b won't be defined yet. Commented Jun 27, 2017 at 14:21
  • 2
    If you turned on any amount of error messaging you would get NOTICE Undefined variable: b on line number 5 pretty simple Commented Jun 27, 2017 at 14:22

4 Answers 4

3

No this is not possible, what you can do is this:

$b = array(
    'a' => 'Adam'
);

$b['b'] = $b['a'] . ' and eve';
Sign up to request clarification or add additional context in comments.

Comments

0

No that is not possible because the array $b hasn't been created yet when you try to add

'b' => $b['a'];

Instead you should create the array $b, then add the other element. Like so:

$b = array('a' => 'Adam');
$b['b'] = $b['a'] . ' and eve';

Comments

0

No not possible, as doing so would produce E_NOTICE : type 8 -- Undefined variable: b -- at line X _where X is the where you are 'b' => $b['a'] assigning a value to b

Comments

0

No, It's not possible, It will give Error like "Undefined variable: b". If you want to perform anyway, use this one

$b = array('a' => 'Adam'); $b['b'] = $b['a'];

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.