1

I have problem. I can't print value of $value->working type unicode in foreach but that not working and i have notification htmlentities() expects parameter 1 to be string, array given I'm using Json. When i echo dd($levelResult) then

array:1 [▼
  0 => "Đại Học"
]

if i echo $levelResult[0] then i have notification Invalid argument supplied for foreach()

@foreach( $search as $key => $value)
    @if(json_decode($value->working,JSON_BIGINT_AS_STRING)[0] != " ")           
         @foreach(json_decode($value->working) as $key => $levelResult)
               <p>{{ $levelResult }} </p>               
         @endforeach
    @else
      {{ " " }}
    @endif
@endforeach
3

1 Answer 1

0

To fix your second issue use json_decode($value->working, true) to parse json in array but not in object.

I would suggest you yo use the following code snippet. The code will parse json once and proper if comparison.

@foreach( $search as $key => $value)
    <?php $result = json_decode($value->working, true, 512, JSON_BIGINT_AS_STRING); ?>
    @if($result[0] != " ")
        @foreach($result as $key => $levelResult)
                   <p>{{ $levelResult[0] }} </p>
        @endforeach
    @else
      {{ " " }}
    @endif
@endforeach
Sign up to request clarification or add additional context in comments.

3 Comments

i will testing :D
@Andreyj Ludinovskov: i used code of you but i still see notification htmlentities() expects parameter 1 to be string, array given at htmlentities(array('Đại Học'), '3', 'UTF-8', false) in helpers.php line 531 i don't know why it's not working :'(
@BiHíp does it make sense to check $result[0] != " " if it's array always?

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.