Федотов
Федотов

Reputation: 121

Output values inside the array

$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
}

Upvotes: 0

Views: 40

Answers (1)

tenshi
tenshi

Reputation: 618

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

Upvotes: 1

Related Questions