lundi 21 août 2023

How Display Random json_decode foreach

I want to display randomly in json_decode foreach. These codes are for Laravel/php.

my table:

id    url        attr
1     post-1     [{"at1":"Attr-A1","at2":"Attr-A2",.....}]

my array (attr):

[{
"at1":"Attr-A1",
"at2":"Attr-A2",
"at3":"Attr-A3",
"at4":"Attr-A4",
},
{
"at1":"Attr-B1",
"at2":"Attr-B2",
"at3":"Attr-B3",
"at4":"Attr-B4",
},
{
"at1":"Attr-C1",
"at2":"Attr-C2",
"at3":"Attr-C3",
"at4":"Attr-C4",
}]

my controller:

$post = Post::where('url',$url)->first();

my blade

@foreach ( json_decode($post->attr, true) as $arr )
    <p></p> ,
    <p></p> ,
    <p></p> ,
    <p></p>
    <br>
@endforeach

Qutput: I want the output to show randomly.

Attr-A1 , Attr-A2 , Attr-A3 , Attr-A4
Attr-C1 , Attr-C2 , Attr-C3 , Attr-C4
Attr-B1 , Attr-B4 , Attr-B3 , Attr-B4

or

Attr-C1 , Attr-C2 , Attr-C3 , Attr-C4
Attr-A1 , Attr-A2 , Attr-A3 , Attr-A4
Attr-B1 , Attr-B4 , Attr-B3 , Attr-B4

shuffle or array_random : These two do not work for me.

Does json_decode display randomly?




Aucun commentaire:

Enregistrer un commentaire