功能没有给出期望的结果

时间:2014-03-31 18:13:14

标签: php

我有一个php函数:

<?php
function find_senior($mylevel, $sender){
    global $class_database;
    global $g_level1;
    global $g_level2;
    global $g_level3;

$sponsor=$class_database->getdata("sponsorid", "id='$sender' AND gift_level > '$mylevel'", "user");
$sponsor2=$class_database->getdata("sponsorid", "id='$sender'", "user");
    if(strlen($sponsor) > '0'){
        if($mylevel < $g_level1){
        return array("id"=>"1", "amt"=>$g_level1, "lvl"=>$g_level1);    
        }
        elseif($mylevel < $g_level2){
        return array("id"=>"1", "amt"=>$g_level2, "lvl"=>$g_level2);    
        }
        elseif($mylevel < $g_level3){
        return array("id"=>"1", "amt"=>$g_level3, "lvl"=>$g_level3);    
        }
    }
    elseif(strlen($sponsor) <='0' && strlen($sponsor2) <='0'){
        if($mylevel < $g_level1){
        return array("id"=>"1", "amt"=>$g_level1, "lvl"=>$g_level1);    
        }
        elseif($mylevel < $g_level2){
        return array("id"=>"1", "amt"=>$g_level2, "lvl"=>$g_level2);    
        }
        elseif($mylevel < $g_level3){
        return array("id"=>"1", "amt"=>$g_level3, "lvl"=>$g_level3);    
        }   
    }
elseif(strlen($sponsor) <='0' && strlen($sponsor2) >'0'){
    find_senior($mylevel, $sponsor2);
    }

}

?>

当我们执行var_dump()

时,它应该作为数组返回
$array=show("100", "2");
var_dump($array);

但它只会返回:

NULL

错误可能在哪里? 我是非常新的php,请尝试解决这个难题,我尝试了很多,但可能是因为我有限的知识我无法解决它

1 个答案:

答案 0 :(得分:0)

应该是:

class myClass{
function show($g_level1, $id){
return array("id"=>$id, "amt"=>$g_level1, "lvl"=>$g_level1);
}
}

现在创建该类的实例:

$instance = new myClass();
$instance->show("100", "2");