2

How to extract only 15 from [{"1":"15"}] in Laravel controller?

$var = array();
$mku = $mark->examMark;
$var[] = json_decode($mku, true);

I have tried using the above code but it doesn't work.

2 Answers 2

1

Do this:

$value = json_decode($mku, true)[1];
Sign up to request clarification or add additional context in comments.

6 Comments

Nop.am not geting any values.
Please show results of dd(json_decode($mku, true));
Here, the call to the controller function is made from angular js function. so from the controller we are returning the value back to the js function. Here dd($value) is not working
Then do \Log::info('Result is: '.json_decode($mku, true)); and see for the result in storage/logs/laravel.log
@Cliffs so, it's json which contains json? Just a guess, but try something like json_decode(json_decode($mku, true), true)[1] then.
|
0

This should work:

$decoded = json_decode($mku, true)[0][1];

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.