-3

I'm trying to set a value of a subkey as another value, but when I try to use $array['Key1']['FullPath'] it returns Array something. How can I solve that? Thanks.

$array = Array(
    'Key1' => Array(
        'Path' => 'http://stackoverflow.com/',
        'FullPath' => ['Path'] . ' something'
    ),
    [...] //another arrays
);
6
  • What is this notation supposed to represent? 'FullPath' => ['Path'] . ' something' Commented Jul 26, 2014 at 4:53
  • I want to use "Path" value on "FullPath" key. Commented Jul 26, 2014 at 4:54
  • That really doesn't clarify. What is currently in your array, and what are you trying to get out? Commented Jul 26, 2014 at 4:55
  • I want to display "stackoverflow.com something" when $array['Key1']['FullPath'] Commented Jul 26, 2014 at 4:56
  • You can't do what (I think) you're trying to do. In any case, this question is still very unclear. Commented Jul 26, 2014 at 4:59

2 Answers 2

0

I dont think that its possible but i could be wrong , u can do this :

$path = 'https://stackoverflow.com/';
$array = Array(
    'Key1' => Array(
        'Path' => $path,
        'FullPath' => $path . ' something'
    ),
    [...] //another arrays
);

oh it turn out what u want is possible PHP: Self-referencing array

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

1 Comment

It works, but I don't want value outside the array.
0

If you want Path is a key, you should change your array struct.

$array = array(
 'Key1' => array(
     'Path' => 'http://stackoverflow.com/',
     'FullPath' => array ( 'Path' => '',
                           'Something' => ' something'
)));

1 Comment

I want the value of this key, not as a string

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.