How to select specific array using if else PHP

132 views Asked by At

I need a little guidance.The scenario is I want to display different outputs based on the array given. For example if the array have specific value it will show that data. I will show an example.

[{"ID":"1","NUMBER":"12345678"},{"numberno":"456789"}]

I already encode the array and the problem now only on the if else . As you can see there is two different variable but I want to declare them AS same variable. This is the code that I have tried

if('ID'=true)
        { 
"SELECT NUMBER AS NO FROM DUAL UNION"
         }
else{
"SELECT numberno AS NUMBER FROM DUAL UNION"
}

So for example on the first array, there is {"ID":"1","NUMBER":"12345678"} so if there is "ID" exist in the array it will select NUMBER else will return numberno . I hope you understand my question. Thank you for your time. This is just an example. even if ur suggestion different , I will use it as reference. Thanks again.

1

There are 1 answers

1
Safwan Al Najjar On

Try this:

if(!ID OR ID='')

{

"SELECT numberno AS NUMBER FROM DUAL UNION"

}

elseif (ID){

"SELECT NUMBER AS NO FROM DUAL UNION"

}