Php 检查是否设置了数组值

Php 检查是否设置了数组值,php,laravel,laravel-5,laravel-5.3,Php,Laravel,Laravel 5,Laravel 5.3,我正在从表中获取练习字符串id和程序字符串id $project_type = DB::table('project') ->where('code',$asset_request->project_code) ->select('practice_string_id','program_string_id') ->first(); print_r($project_type); //ou

我正在从表中获取练习字符串id和程序字符串id

$project_type = DB::table('project')
              ->where('code',$asset_request->project_code)
              ->select('practice_string_id','program_string_id')
              ->first();
print_r($project_type); //output 
输出:

stdClass对象([practice\u string\u id]=>PRACTICE0028 [程序\u字符串\u id]=>)

我想检查$project\U type->program是否已设置为if状态

if(isset($project_type->program_string_id)){
    //nothing in $project_type->program but reached here now 
}

我想知道如何在php中检查值是否设置为if condition。现在
如果(isset($project\u type->program\u string\u id))
通过并且条件是否有效。我想跳过if condition。

因为这是一个数据库查询,并且您选择字段
program\u string\u id
,它将始终和任何时候设置。问题是,是否有任何价值。因此,您可能希望使用
作为检查:

if (!empty($project_type->program_string_id)) {
    // ...
}

您必须同时使用
isset()
empty()
否则在某些情况下可能会引发错误

,问题是什么?你在找什么?你能更精确地解释一下你想要实现什么吗?你的意思是如果$project\U type->program\U string\U id设置在$project\U type中,我想OP不理解isset
或array的意思。
$project_type = DB::table('project')
              ->where('code',$asset_request->project_code)
              ->select('practice_string_id','program_string_id')
              ->first();
if(count($project_type) > 0 && $project_type != ""){

    echo $project_type->program_string_id;
}
$project_type = DB::table('project')
              ->where('code',$asset_request->project_code)
              ->select('practice_string_id','program_string_id')
              ->first();
if(count($project_type) > 0 && $project_type != ""){

    echo $project_type->program_string_id;
}