I want to match string with array. I am retrieving the status code from status table in the database...I have a json file with code and name...Based on the status code returned from db i need to match this code in json file and display the status name in foreach
Please anyone help
Thanks
statuscodes array
[
{
"code":"0",
"name":"AB"
},
{
"code":"1",
"name":"CD"
},
{
"code":"2",
"name":"XY"
},
{
"code":"10",
"name":"EF"
},
{
"code":"12",
"name":"FG"
}
]
<?php $findproducts = \DB::table('status')->select('id', 'status_name', 'ab', 'status_code','created_at')->where('ab', $track->ab)->orderBy('id', 'DESC')->get(); ?>
String Pos....
@foreach($findproducts as $pr)
@if($statuscodes != null)
@foreach ($statuscodes as $stcode)
@if (strpos($pr->status_code, $stcode['code']) !== FALSE)
{{ $stcode['name']." " .$stcode['code'] }}
@endif
@endforeach
@endif
@endforeach
The output which i am getting from above is
CD 1 XY 2 FG 12
CD 1 AB 0 EF 10
XY 2
CD 1
AB 0
Expected Output should be
FG 12
EF 10
XY 2
CD 1
AB 0

orderBy('id', 'DESC')toorderBy('code', 'DESC')?1,2and12it will output these. If I got your expected output correctly you want to output thestatuscodesarray elements and not the products, correct?strpos($pr->status_code, $stcode['code']). Can you explain more what you want to do as your example is not understandable by me... What do you really want to do ? Also what version of PHP are you using ?