0
$stock = [ "marketplace" => [ "stocks" => 'if($a = 1) {return 6}' ] ]; 

How to use the code inside the array value ?

return $stock['marketplace']['stocks']; 

I plan to get in the method

if($a = 1) { return 6 } 
3
  • You wish to execute it or simply return it? Commented Mar 3, 2022 at 8:00
  • Execute, I want to use this as part of the code Commented Mar 3, 2022 at 8:01
  • 1
    ok, I wouldn't recommend this approach, so I am out. BTW, if($a = 1) { will always be true since it is an assignment. You would rather wish to do if($a == 1) { Commented Mar 3, 2022 at 8:03

1 Answer 1

1

If you want to execute the code, you can do:

eval($stock['marketplace']['stocks']); 

but as @nice_dev said it is not recommended to use eval

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.