开发者

conditional in_array trouble with PHP mySQL

I have firePHP so i know exactly what the variables are, but I can't figure out why this code doesn't chan开发者_JAVA百科ge it.

I receive from a mySQL call $query (which if returned produces [{"type":"2"}]) I have 4 potential types, and things can be multiple types (i.e. [{"type":"1"},{"type":"2"}])

Now I want to read this data and run various other functions based on the type it has, that is: if it's only type 2, call function TWO, if it's type 1 and 2 call function ONE and function TWO. I thought this would be easiest if i moved all the data into another array.

Here is the code I currently have:

$result = array('message'=>false, 'money'=>false, 'glasses'=>false, 'exclamation'=>false);
    if (in_array('1',$query)) {$result['message'] = true;}
    if (in_array('2',$query)) {$result['money'] = true;}
    if (in_array('3',$query)) {$result['glasses']=true;}
    if (in_array('4',$query)) {$result['exclamation']=true;}
    echo json_encode($result);

This however does not update the $result array (as I can tell all of the values of $message are false in firePHP.... Thus I assume something is wrong with my if statements, but what?


I´m not sure about the value of $query, but if it is something like:

array [0 => '{"type":"2"}']

You would have to use:

in_array('{"type":"2"}',$query)

as that is the value of your variable.


Is it because the results returned in $query are arrays of arrays, and thus in_array is only searching at the top level and not sub-levels? It seems like what you want is to recursively search $query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜