0

I have a question about using variables inside a function. The first part of code is not working. It appears that the variable '$myvalue' is not being served to the function although when I echo the $myvalue it has the right text.

If I however use normal text, it WORKS!
How to do this dynamically so that the varibale CAN be used?

First code is here and is NOT working!

<?php 
$myregions = array('delaware','florida','colorado');
foreach ($myregions as $myvalue){
osc_query_item(array('region'=>$myvalue));
    if ( osc_has_custom_items() && osc_item_region()==$myvalue) {
        bender_draw_item($class);
    } 
}
?>

Second code is here and IS working!

<?php 
osc_query_item(array('region'=>'Delaware'));
    if ( osc_has_custom_items() && osc_item_region()=='Delaware') {
        bender_draw_item($class);
    } 

    osc_query_item(array('region'=>'Florida'));
    if ( osc_has_custom_items() && osc_item_region()=='Florida')  {
        bender_draw_item($class);
    } 

    osc_query_item(array('region'=>'Colorado'));
    if ( osc_has_custom_items() && osc_item_region()=='Colorado') {
        bender_draw_item($class);
    } 

   ?>

The function is here (I took some of the 'case' out because readability:

function osc_query_item($params = null) {
    $mSearch = Search::newInstance();
    if($params==null) {
        $params = array();
    } else if(is_string($params)){
        $keyvalue = explode("=", $params);
        $params = array($keyvalue[0] => $keyvalue[1]);
    }
    foreach($params as $key => $value) {
        switch($key) {
        case 'region':
            case 'region_name':
                $tmp = explode(",", $value);
                foreach($tmp as $t) {
                    $mSearch->addRegion($t);
                }
                break;

            case 'city':
            case 'city_name':
                $tmp = explode(",", $value);
                foreach($tmp as $t) {
                    $mSearch->addCity($t);
                }
                break;
                }
    }
    View::newInstance()->_exportVariableToView("customItems", $mSearch->doSearch());
}
3
Contributors
2
Replies
22
Views
4 Years
Discussion Span
Last Post by IIM
0

You tried trimming it. It might have some white space around it. The only other thing I noticed that was different is you have capitals for 'D' delaware but not in the array example...

Edited by iamthwee

0

Both seems same except for capital latters in second example.In second one you are taking first letters as capital but not in previous example.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.