Home > Software design >  Split String to get an Array
Split String to get an Array

Time:02-01

In Database :- "["http://localhost//image/aeefb050911334869a7a5d9e4d0e1689.jpg","http://localhost//image/959776b99b006e5785c3a3364949ce47.jpg"]"

After Json_decode = ["http://localhost//image/aeefb050911334869a7a5d9e4d0e1689.jpg","http://localhost//image/959776b99b006e5785c3a3364949ce47.jpg"]

Output i Want:- [0] - http://localhost//image/aeefb050911334869a7a5d9e4d0e1689.jpg [1] - http://localhost//image/959776b99b006e5785c3a3364949ce47.jpg

Code:-

   @if(is_array(json_decode($data->item_image)))
                                    @php $image = json_decode($data->item_image);
                                    @endphp
                                            @foreach($image as $key=>$row)
                                                @if($key == 0)
                                                <div class='carousel-item active'>
                                                    <!-- <img class='img-size img-responsive' src="{{ asset('image/'. $row) }}" /> -->
                                                    <img class='img-size img-responsive' src="{{ $row }}" />
                                                </div>
                                                @else
                                                <div class='carousel-item'>
                                                    <!-- <img class='img-size' src="{{ asset('image/'. $row) }}" /> -->
                                                    <img class='img-size' src="{{ $row }}" />
                                                </div>
                                                @endif
                                            @endforeach
                                    @else

                                    @endif

CodePudding user response:

you can use this

$str = '["http://localhost//image/aeefb050911334869a7a5d9e4d0e1689.jpg",
"http://localhost//image/959776b99b006e5785c3a3364949ce47.jpg"]';
eval("\$myarray = $str;");
print_r($myarray);

CodePudding user response:

 @if(json_decode($data->item_image) != '')
                                    @php $image = json_decode($data->item_image);
                                            eval("\$myarray = $image;");
                                    @endphp
                                            @foreach($myarray as $key=>$row)
                                                @if($key == 0)
                                                <div class='carousel-item active'>
                                                    <!-- <img class='img-size img-responsive' src="{{ asset('image/'. $row) }}" /> -->
                                                    <img class='img-size img-responsive' src="{{ $row }}" />
                                                </div>
                                                @else
                                                <div class='carousel-item'>
                                                    <!-- <img class='img-size' src="{{ asset('image/'. $row) }}" /> -->
                                                    <img class='img-size' src="{{ $row }}" />
                                                </div>
                                                @endif
                                            @endforeach
                                    @else

                                    @endif
  •  Tags:  
  • Related