Dynamic Variables Within Functions

Posted by Ryan on Stack Overflow See other posts from Stack Overflow or by Ryan
Published on 2010-05-22T03:52:45Z Indexed on 2010/05/22 4:00 UTC
Read the original article Hit count: 283

Filed under:
|
|

Why does this work:

function myfunction($v) {
    $query = $v['host'] == '1';
    return ( $query );
}

$output = array_filter($recordset,myfunction);
print_r($output);

Whereas this script, which tries to accomplish the same thing with variables, does not?

$column1 = 'host';
$value1 = 1;
$query1 = '$v[\''.$column1.'\'] == '.$value1;

function myfunction($v) {
    $query = $GLOBALS['query1'];
    return ( $query );
}

$output = array_filter($recordset,myfunction);
print_r($output);

Any help would be great. Thanks!

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays