Syntax error in PHP reset() command

Asked

Viewed 48 times

0

This syntax is incorrect?

$impostos[$value['prod']['cProd']]['ICMS']['vicms']=reset($value['imposto']['ICMS'])['vICMS'];

my doubt is in relation to the command reset() can be used this way

Is making a mistake 500 Internal Server Error na my PHP page

And when I open it with Dreamweaver it’s indicating that this line is incorrect

  • What mistake? What’s going on?

  • the ['vICMS'] should be within parentheses, you need to enable the errors, so, ini_set('display_errors', true); error_reporting(E_ALL);

  • it’s actually right this way, because I need to get the first item of the array and inside get the ['vICMS'] so if I let him into parentheses it wouldn’t work @rray

  • reset($value['imposto']['ICMS']); $impostos .... = $value .... ['vICMS'] resolve? trade the points by long rs

  • It depends on the version of your PHP, if it is 5.3 below does not accept this: reset($value['imposto']['ICMS'])['vICMS']

  • @gabrieloliveira worse than, the version I’m wearing is the 5.5.9

  • You can put a snippet of the return of this array?

  • 1

    Are you sure the error is there in this line? The ideal is to activate the error display to show more details. In Dreamweaver is configured that version of PHP you are using?

  • 1

    Problem Solved!

Show 4 more comments

1 answer

3


A tip is to activate the error display while developing, makes it easier to find the problems.

If you want to try another way with the reset() function, you can assign the return in a variable and access the index you want:

$firstElement = reset($value['imposto']['ICMS']);
$impostos[$value['prod']['cProd']]['ICMS']['vicms'] = $firstElement['vICMS'];
  • 1

    I think that’s the passage you referred to: $impostos[$value['prod']['cProd']]. And in this case it’s correct. It just gets a little difficult to visualize by so many apertures and closing brackets.

  • You can put a snippet of the return of this array?

  • In this case, the $value['Prod']['cProd'] would be any value, like 1. And in this case, this call would be like this: $impostos[1]. That’s why I said it wasn’t incorrect. But to set the error the ideal is to enable error display as you said.

  • Problem Solved!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.