2239 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Sells items exclusively on Envato Market
  • Won a competition
+13 more
mpc
says

Hi guys, I want to store the array ‘path’ in the variable so I can generate it dynamically but I am having trouble with using it later… here is an example:

$my_path = '[something][value]';

echo $my_array{$my_path};

Any idea how to make it work?

812 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
iamthwee
says

You need to reference the element in the array as it is a multidimensional array.

2239 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Sells items exclusively on Envato Market
  • Won a competition
+13 more
mpc
says

LOL :D I know, the $my_array has both something and value fields thats not the problem, this is just an example… the question is how to reference element in an array when you have path in variable.

812 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
iamthwee
says

What?

You’ll have to elaborate, please give a more extensive example.

3072 posts
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Had an item featured on Envato Market
+5 more
wickedpixel
says

maybe is too advanced for me… but what is with the curly braces?

812 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
iamthwee
says

maybe is too advanced for me… but what is with the curly braces?

It’s essentially wrong, you would only use curly braces around clauses such as if/while or defining functions and classes.

My guess is the OP made a typo…

2239 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Sells items exclusively on Envato Market
  • Won a competition
+13 more
mpc
says

I find the example of using the curly braces somewhere on the web, I don’t want to use them I am just trying to figure a way to make it work and I know that the curly braces are wrong, so I need another solution :)

812 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
iamthwee
says

Again we’re going to need a better example…

3072 posts
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Had an item featured on Envato Market
+5 more
wickedpixel
says
so… you generate a $my_path from two strings?
$my_path = $first_string.$second_string;
then use that so search for a value in an array?
$value = $my_array[$my_path];

being this dynamic probably is better if you search first if the array has that key in it ?

if (array_key_exists($my_path, $my_array)) {
$value =  $my_array[$my_path];
}

or else you will get errors..

2239 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Sells items exclusively on Envato Market
  • Won a competition
+13 more
mpc
says

Hmm but wont I get path like this:

$my_array[[something][value]]

// and what I really need is 

$my_array[something][value]

// or is it the same in php?

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by